Python Text Processing - 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.
Example - Extracting Email
main.py
import re
text = "Please contact us at contact@tutorialspoint.com for further information." + \
" You can also give feedbacl at feedback@tp.com"
emails = re.findall(r"[a-z0-9\.\-+_]+@[a-z0-9\.\-+_]+\.[a-z]+", text)
print(emails)
Output
When we run the above program, we get the following output
['contact@tutorialspoint.com', 'feedback@tp.com']