We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Validating and Parsing Email Addresses
Validating and Parsing Email Addresses
Sort by
recency
|
360 Discussions
|
Please Login in order to post a comment
I didn't use emails.utils for my solution. Find my code below.
Just to precise, I started by splitting username / domain and extension into differents variables, then, I have created 3 differents regex pattern, to check if each one works.
When it was done, I've removed the split for username / domain and extension, then merge the 3 differents regex pattern into a big one.
And finally, it pass all the tests :
from email.utils import parseaddr import re
pattern = r'^[A-Za-z][a-zA-Z0-9.,-_]*@[a-zA-Z]+.[a-zA-Z]{1,3}$' input_no = input() address = [] for i in range(int(input_no)): e_input = input() address.append(e_input)
for i in range(int(input_no)): name,addr = parseaddr(address[i]) match = re.match(pattern,addr) if match: print(name + "<" + addr + ">") print('Valid email')
This was a very simple challenge. ~~Even without using
email.utils
, it would've been simple.~~Update: I changed my submission to not use
email.utils
, just to be shorter and to depend on fewer modules. Basically, it's the simplest possible program to read all input lines and output only those that match a regex.how to solve this code