Python extract emails from text
Extracting Emails from Text in Python
To extract emails from text, we can use regular expressions. In the following example, we use the regex package to define a pattern for email IDs and then use the findall() function to retrieve text that matches this pattern.
import re
text = "Please contact us at contact@tutorialspoint.com for further information."+
" You can also provide feedback at feedback@tp.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:
['contact@tutorialspoint.com', 'feedback@tp.com']