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 [EMAIL PROTECTED], which is not valid. Here's > my attempt, neither of my regexps work quite how I want: > > [code] > import os > import re > > s = 'Hi [EMAIL PROTECTED] [EMAIL PROTECTED] [EMAIL PROTECTED] @@not > [EMAIL PROTECTED] partridge in a pear tree' > r = re.compile(r'[EMAIL PROTECTED]@\s]+\.\w+') > #r = re.compile(r'[EMAIL PROTECTED]') > > addys = set() > for a in r.findall(s): > addys.add(a) > > for a in sorted(addys): > print a > [/code] > > This gives: > [EMAIL PROTECTED] > [EMAIL PROTECTED] > [EMAIL PROTECTED] <-- shouldn't be here :( > [EMAIL PROTECTED] > > Nearly there but no cigar :) > > I can't see the wood for the trees now :) Can anyone suggest a fix > please? > The problem is that your pattern doesn't start out by confirming that it's either at the start of a line or after whitespace. You could do this with a "look-behind assertion" if you wanted.
regards Steve -- Steve Holden +44 150 684 7255 +1 800 494 3119 Holden Web LLC/Ltd http://www.holdenweb.com Skype: holdenweb http://holdenweb.blogspot.com Recent Ramblings http://del.icio.us/steve.holden -- http://mail.python.org/mailman/listinfo/python-list