Skip to content

Instantly share code, notes, and snippets.

@sh78

sh78/extract-email.py

Last active Jun 5, 2018
Embed
What would you like to do?
#!/usr/bin/env python3
import fileinput
import re
##
# Extract email addresses from file or `stdin`
#
# Prints out a standard list of email address substrings contained in `fileinput`
# Call on a file or pipe to `stdin`
#
# extract-email.py messy_file.txt
# ./some-script --messy | extract-email.py | sort | unique > emails.txt
##
regex = re.compile(r"\S*\@\S*")
string = ""
for line in fileinput.input():
string += line
matches = re.findall(regex, string) # => array
print("\n".join(matches))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment