I'm trying to find a pattern to match an email address. The point is because I have some text with email addresses typed in, but I want to automatically turn them into mailto: links in HTML. I started off with something horribly complex, but then realized I was going to have to construct it in steps. I'm not new to regexes, just using them in Vim. So here was my first idea (by the way, it's "magic", not "nomagic"):
/[^\s]\+@[^\s\.]\+\.[^\s\.]\+/
So I'm thinking it should be a word, followed by an at-sign, followed by the domain, then a dot, then the TLD. But the problem is this doesn't match an email address for some reason. Here's some example text:
Taylor Venable, MetaSyntax Inc., Chief Technical Officer, (260) 867-5309,
taylor@metasyntax.net
This pattern doesn't match at all within this text. So I tried to break it down further:
/[^\s]\+@/
This matches the start of the text, where my name is. I don't know why. I read that \s doesn't work for multi-byte text, so I tried \p instead of [^\s] but I get the same result. Furthermore, this works:
/\p*@/
But unfortunately also matches the at-sign at the start of some text, which is wrong because that's not a valid email address.
Obviously I'm missing something in the way Vim pattern matching works. Any pointers on the topic (and in this particular case) are greatly appreciated. Thanks!