Extract Email ID from URL Text File in Python



Here we are using regular expression package for extracting email-id from the URL-text file. Given the URL- text file. Using regular expression package we define the pattern of email-id then use findall() function, using this method to check the text which will match with this pattern.

Input
text= Please contact us at contact@tutorialspoint.com for further information."+\  " You can also give feedback at feedback@tutorialspoint.com"
Output ['contact@tutorialspoint.com ','feedback@tutorialspoint.com']

Example code

import re
my_text = "Please contact us at contact@tutorialspoint.com for further information."+\
   " You can also give feedback at feedback@tutorialspoint.com"
my_emails = re.findall(r"[a-z0-9\.\-+_]+@[a-z0-9\.\-+_]+\.[a-z]+", my_text)
print (my_emails)

Output

['contact@tutorialspoint.com', 'feedback@tutorialspoint.com']
Updated on: 2019-07-30T22:30:23+05:30

311 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements