Python - Extract Emails from Text
To extract emails form text, we can take of regular expression. In the below example we take help of the regular expression package to define the pattern of an email ID and then use the findall() function to retrieve those text which match this pattern.
import re text = "Please contact us at firstname.lastname@example.org for further information."+\ " You can also give feedbacl at email@example.com" emails = re.findall(r"[a-z0-9\.\-+_]+@[a-z0-9\.\-+_]+\.[a-z]+", text) print emails
When we run the above program, we get the following output −