a more precise re for email addys

rbt rbt at athop1.ath.vt.edu
Wed Jan 18 14:01:24 EST 2006


Is it possible to write an re that _only_ matches email addresses? I've 
been googling around and have found several examples on the Web, but all 
of them produce too many false positives... here are examples from 
Google that I've experimented with:

re.compile('([\w\.\-]+@[\w\.\-]+)')
re.compile(r'[\w\-][\w\-\.]+@[\w\-][\w\-\.]+[a-zA-Z]{1,4}')
re.compile('(\S+)@(\S+)')

All of these will find email addys, but they also find other things. 
Could someone demonstrate how to write a more accurate re for emails?

BTW, this is not for spam, but like any tool could be used in a bad way.

Thanks!



More information about the Python-list mailing list