[code.view]

[top] / python / PyMOTW / re / re_email_compact.py

     #!/usr/bin/env python
     # encoding: utf-8
     #
     # Copyright (c) 2010 Doug Hellmann.  All rights reserved.
     #
     """Match email addresses
     """
     #end_pymotw_header
     
     import re
     
     address = re.compile('[\w\d.+-]+@([\w\d.]+\.)+(com|org|edu)', re.UNICODE)
     
     candidates = [
         u'first.last@example.com',
         u'first.last+category@gmail.com',
         u'valid-address@mail.example.com',
         u'not-valid@example.foo',
         ]
     
     for candidate in candidates:
         print
         print 'Candidate:', candidate
         match = address.search(candidate)
         if match:
             print '  Matches'
         else:
             print '  No match'
         
     

[top] / python / PyMOTW / re / re_email_compact.py

contact | logmethods.com