Reading Time: 1 minutes
Extract information from an email address in Python
Write a Python program to extract information from an email address. Given that you are provided an email address in the format firstname.lastname@organization.com and there are no numbers in the email address, write a Python program to extract the first name, last name and organization name from it.
import re
sampleEmail = 'ethan.hunt@imf.com'
matchedObject = re.search('(\w+)\.(\w+)@(\w+)\.com', sampleEmail)
print( matchedObject.groups() ) # ('ethan', 'hunt', 'imf')
To learn more about Regular Expressions in Python, click here.







