[prev in list] [next in list] [prev in thread] [next in thread] 

List:       python-list
Subject:    Re: I need some help with a regexp please
From:       "richard.charts () gmail ! com" <richard ! charts () gmail ! com>
Date:       2006-09-21 17:29:04
Message-ID: 1158859744.288230.232930 () m7g2000cwm ! googlegroups ! com
[Download RAW message or body]


codefire wrote:
> Hi,
>
> I am trying to get a regexp to validate email addresses but can't get
> it quite right. The problem is I can't quite find the regexp to deal
> with ignoring the case james..kirk@fred.com, which is not valid. Here's
> my attempt, neither of my regexps work quite how I want:
>
> [code]
> import os
> import re
>
> s = 'Hi james..kirk@fred.com dr.spock@blarg.com jim@home.com @@not
> scottie@home.space.com partridge in a pear tree'
> r = re.compile(r'\w+\.?\w+@[^@\s]+\.\w+')
> #r = re.compile(r'[a-z\-\.]+@[a-z\-\.]+')
>
> addys = set()
> for a in r.findall(s):
>     addys.add(a)
>
> for a in sorted(addys):
>     print a
> [/code]
>
> This gives:
> dr.spock@blarg.com
> jim@home.com
> kirk@fred.com   <-- shouldn't be here :(
> scottie@home.space.com
>
> Nearly there but no cigar :)
>
> I can't see the wood for the trees now :) Can anyone suggest a fix
> please?
>
> Thanks,
> Tony

'[\w.]+@\w+(\.\w+)*'
Works for me, and SHOULD for you, but I haven't tested it all that
much.
Good luck.

-- 
http://mail.python.org/mailman/listinfo/python-list
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic