Help with Regular Expressions matching

Peter Abel p-abel at t-online.de
Mon Feb 3 12:10:09 EST 2003


Tim Roberts <timr at probo.com> wrote in message news:<uunr3vgedknqgg372j70ijqucgj44k6s32 at 4ax.com>...
> p-abel at t-online.de (Peter Abel) wrote:
> >
> >But all the ugly emails like e.g.:
> >>>> re.match(r'^.*?@\w?\.?domain\.com$','!"=?+#@b.domain.com').group()
> >'!"=?+#@b.domain.com'
> >I don't know the excact rules to perform a valid email,
> >but the above one doesn't seem valid to me.
> 
> In fact, virtually any set of printable ASCII characters is a valid e-mail
> username by RFC822.
> 
> >Though I'm not sure if
> >>>> re.match(r"^[\w.-]+@(sub\.)?domain.com$",'.-.-.- at domain.com').group()
>  '.-.-.- at domain.com'
> >>>> 
> >is a valid email.
> 
> Yes, it is perfectly legal.  Even your own e-mail address has a dash in it,
This is why I put the dash and the dot into the re.
> and I'm sure you've seen many addresses with dots.
My email should start with p.abel but somebody with the
same name stole <wink> my good email-alias during the minutes
when I had to release it to change from ISDN to DSL.

But even if you say > ... any set of printable ASCII characters is a 
                    >     valid e-mailusername by RFC822.
I wouldn't like to have an email like ".-.-.- at domain.com", and I thought
about making the re more restrictive, something like
r'[a-zA-Z][\w-]*?(\.[a-zA-Z][\w-]*?)*?@and.so.on'.
On the other side why should I not have an email as 
   ":-)@sub.domain.com"
But how would I spell this to my friend?
My email is  "smiley at sub dot domain dot com" <wink>

Regards
Peter




More information about the Python-list mailing list