[ Web Proxy ]
URL:
Viewing: https://www.tutorialspoint.com/python_text_processing/python_extract_emails_from_text.htm [Back]  [Original]

Python Text Processing - Extract Emails from Text
Tutorials Courses Jobs Login

Python Text Processing Useful Resources

Selected Reading
Home Python_text_processing Python Text Processing - Extract Emails from Text

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']
Tutorix - AI Tutor [Tutorix - AI Tutor]
Print Page
Advertisements

Web Proxy Viewer  |  New URL  |  Original Page