python regexp to find part of an email address

Solutions on MaxInterview for python regexp to find part of an email address by the best coders in the world

showing results for - "python regexp to find part of an email address"
Solène
28 May 2019
1# Visit: https://regexr.com/
2# and look at the Menu/Cheatsheet
3import re
4
5# Extract part of an email address
6email = 'name@surname.com'
7
8# Option 1
9expr = '[a-z]+'
10match = re.findall(expr, email)
11name = match[0]
12domain = f'{match[1]}.{match[2]}'
13
14# Option 2
15parts = email.split('@')