Python @ DjangoSpin

PyPro #73 Extract information from an email address

Buffer this pageShare on FacebookPrint this pageTweet about this on TwitterShare on Google+Share on LinkedInShare on StumbleUpon
Reading Time: 1 minutes

Extract information from an email address in Python

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.


See also:

Buffer this pageShare on FacebookPrint this pageTweet about this on TwitterShare on Google+Share on LinkedInShare on StumbleUpon

Leave a Reply