Python – Extracting Email Addresses from Text
Python – Extracting Email Addresses from Text
To extract email addresses from text, we can use regular expressions. In the following example, we use the regular expression package to define a pattern for email IDs and then use the findall() function to retrieve text that matches the pattern.
import re
text = "Please contact us at contact@tutorialspoint.com for more 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']