a more precise re for email addys

Steven D'Aprano steve at REMOVEMEcyber.com.au
Thu Jan 19 05:21:50 CET 2006


skip at pobox.com wrote:
>     rbt> re.compile('([\w\.\-]+@[\w\.\-]+)')
>     rbt> re.compile(r'[\w\-][\w\-\.]+@[\w\-][\w\-\.]+[a-zA-Z]{1,4}')
>     rbt> re.compile('(\S+)@(\S+)')
> 
>     rbt> All of these will find email addys, but they also find other
>     rbt> things.
> 
> I think the only way to decide if your regular expression does what you want
> is to provide a set of strings it must accept and another set which it must
> reject.  Supply those two sets and I'm sure any number of people here can
> come up with a regular express that distinguishes the two sets.

Doesn't the relevent RFC state that the only way to 
determine a valid email address is to send to it and 
see if the mail server likes it?

I believe it explicitly warns against validating email 
addresses, since you will invariably end up refusing to 
accept some valid email addresses.


-- 
Steven.




More information about the Python-list mailing list