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

List:       python-list
Subject:    I need some help with a regexp please
From:       "codefire" <tony.bedford () gmail ! com>
Date:       2006-09-21 17:14:42
Message-ID: 1158858881.894280.93230 () d34g2000cwd ! googlegroups ! com
[Download RAW message or body]

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

-- 
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