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.
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.
import re, sys
# I included support for "+" in the address.
# I hate when email address validators don't allow it.
# Note that this is only a regex exercise, not a real email
# address validation. The ONLY TRUE way to validate an
# email address is to send a message to it and instruct the
# recipient to respond. When their response is received, ONLY
# THEN can the email address be considered valid.
print(''.join(l for l in sys.stdin.readlines()[1:]
if re.search(r'<[a-z][\w.+-]*@[a-z]+\.[a-z]{1,3}>', l, re.I)))
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Validating and Parsing Email Addresses
You are viewing a single comment's thread. Return to all comments →
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.