Python Program to extract email-id from URL text file

PythonProgrammingServer Side Programming

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’]
raja
Published on 22-Nov-2018 05:46:59
Advertisements