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 [email protected] for further information."+\ " You can also give feedbacl at [email protected]" emails = re.findall(r"[a-z0-9\.\-+_][email protected][a-z0-9\.\-+_]+\.[a-z]+", text) print emails
When we run the above program, we get the following output −
>['[email protected]', '[email protected]']