LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 01-31-2007, 01:23 PM   #1
taylor_venable
Member
 
Registered: Jun 2005
Location: Indiana, USA
Distribution: OpenBSD, Ubuntu
Posts: 892

Rep: Reputation: 43
Question Vim - Pattern to match email address


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!
 
Old 01-31-2007, 03:54 PM   #2
gilead
Senior Member
 
Registered: Dec 2005
Location: Brisbane, Australia
Distribution: Slackware64 14.0
Posts: 4,141

Rep: Reputation: 168Reputation: 168
Have you tried /\S\+@\S\+
That seems to work with Vim 7.0 here.
 
Old 01-31-2007, 04:56 PM   #3
taylor_venable
Member
 
Registered: Jun 2005
Location: Indiana, USA
Distribution: OpenBSD, Ubuntu
Posts: 892

Original Poster
Rep: Reputation: 43
Thanks! That does it. I still don't understand why \p and [^\s] don't work as I expect them to, so if anyone can enlighten me as to why this is, I'd be much obliged. But I'm happy for your solution, gilead.
 
  


Reply

Tags
pattern, vim


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
printing pattern match and not whole line that matches pattern Avatar33 Programming 13 05-06-2009 06:17 AM
Pattern match and counting script -->how to write ? froglinux LQ Suggestions & Feedback 4 06-11-2006 06:10 PM
how to use the sed w option to redirect pattern match to file nickleus Linux - General 11 04-18-2006 08:34 AM
perl pattern match question lluciano Programming 4 02-28-2006 05:59 AM
svcadm: Pattern 'apache' doesn't match any instances xpucto Solaris / OpenSolaris 8 02-19-2006 07:30 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 11:28 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration