Skip to content

Instantly share code, notes, and snippets.

@jimr
Created July 21, 2014 08:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimr/8c0521c36add08219c69 to your computer and use it in GitHub Desktop.
Save jimr/8c0521c36add08219c69 to your computer and use it in GitHub Desktop.
Good Enough(TM) email address finder
import re
pattern = re.compile(
r'(mailto:)?(?P<email>[^(\s|<|\[))]*@[^\s]*\.[^(\s|>|;|,|\])]*)'
)
test_data = '''
This is a@b.com string with some Email Addresses
<email@addresses.com> in it. There are also
some mailto:test@example.com addresses in here too.
'''
for match in pattern.finditer(test_data):
print match.groupdict().get('email')
# would print:
# a@b.com
# email@addresses.com
# test@example.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment