OT: regex to find email

Josh Close narshe at gmail.com
Tue Sep 21 11:48:29 EDT 2004


On Tue, 21 Sep 2004 17:08:47 +0200, Remy Blank
<remy.blank_asps at pobox.com> wrote:
> 
> 
> Josh Close wrote:
> > I've been trying to find a good regex to parse emails, but haven't
> > found any to my liking. I basically need to have
> >
> > ( r'[a-z0-9\.\-\_]@[a-z0-9\.\-\_]', re.IGNORECASE )
> >
> > but the first part can't start with .-_ and the last part has to have
> > a . in it (first/last being before/after the @).
> 
> I'd try something like (untested):
> 
> [a-z0-9][a-z0-9\._-]*@[a-z0-9\._-]+\.[a-z0-9\._-]+
> 
> Basically, you have to remember to say *how many* characters you want
> of a specific set, that's what the '*' and '+' are for.
> 
> -- Remy
> 
> Remove underscore and suffix in reply address for a timely response.
> 
> 
> 
> --
> http://mail.python.org/mailman/listinfo/python-list
> 


Ok, I see how this works.... but now how would I add {3,64} for the id
and {3,255} for the domain? I forgot to throw that part in earlier. I
believe a valid id is 3-64 chars and domain is 3-255 chars.

So basically like this

[\w[\w\._-]*]{3,64}@[[\w\._-]{3,255}\.[\w\._-]+]

......I know that won't work, but I'd like to verify that the id is
3-64 chars long, and doesn't start with -._ and the domain is 3-255
chars long and doesn't start with -._ but must have a dot and tld's
like .com.au need to be accounted for also.

-Josh



More information about the Python-list mailing list