Last active
August 29, 2015 14:05
-
-
Save yeukhon/565f23a77d3d58c1cf02 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
text1 = "[email protected]" | |
text2 = "[email protected]" | |
r1 = re.compile(r'[a-zA-Z0-9]+@[a-zA-Z]+\.[a-zA-Z]+(\.[a-zA-Z]+)*') | |
print(r1.match(text1).group()) | |
print(r1.match(text2).group()) | |
print("part 2 - compare with and without (?:") | |
r2 = re.compile(r'[a-zA-Z0-9]+@[a-zA-Z]+\.[a-zA-Z]+(?:\.[a-zA-Z]+)*') | |
print(r1.findall(text2)) | |
print(r2.findall(text2)) | |
print("part 3 - udacity assignment") | |
def addresses(haystack): | |
emails = re.findall(r'\w+@[a-zA-Z]+\.[a-zA-Z]+(?:\.[a-zA-Z]+)*', haystack) | |
return [re.sub("NOSPAM", "", email) for email in emails] | |
input1 = """[email protected] (1814-1871) was an advocate for | |
democracy. [email protected] (1905-1982) wrote about | |
the early nazi era. [email protected] was honored with a 1994 | |
deutsche bundespost stamp. seti@home is not actually an email address.""" | |
output1 = ['[email protected]', '[email protected]', '[email protected]'] | |
print addresses(input1) == output1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment