Reputation: 1726
I am trying to identify and extract emails from sentences. sample example sentences with emails.
sen1 = "Please send an email to [email protected]"
sen2 = "reply to us on [email protected]"
sen3 = "mailing address: [email protected]"
I tried using information from this link and this link, and found one expression working for sen1 and sen2
re.findall('\w+?@\w+?\x2E.+', sen1)
I have no problem in identifying for sen1 and sen2. but for sen3 the email has '.' between, so i tried with many trails
re.findall('\w+?\x2E.+@\w+?\x2E.+', sen3)
re.findall('([-!#-'*+/-9=?A-Z^-~]+(\.[-!#-'*+/-9=?A-Z^-~]+)*|"([]!#-[^-~ \t]|(\\[\t -~]))+")@[0-9A-Za-z]([0-9A-Za-z-]{0,61}[0-9A-Za-z])?(\.[0-9A-Za-z]([0-9A-Za-z-]{0,61}[0-9A-Za-z])?)+', sen3)
re.findall( ,sen3)
I could not even understand what the complicated expression is doing, it returns an empty list ([]) even for sen1 and sen2. how to identify such emails as in sen3?
Upvotes: 1
Views: 43
Reputation: 43169
You could try
\S+@\S+
and verify later if the address actually exists, see a demo on regex101.com.
Upvotes: 1