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
|
357 Discussions
|
Please Login in order to post a comment
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
import re import email.utils
pattern = r'^[a-zA-Z][\w.-]*@[a-zA-Z]+.[a-zA-Z]{1,3}$'
n = int(input()) for _ in range(n): line = input() name, addr = email.utils.parseaddr(line) if re.fullmatch(pattern, addr): print(email.utils.formataddr((name, addr)))
import re pattern = r'^[a-zA-z][a-zA-Z0-9_.-]*@[a-z]+.[a-z]{1,3}$'
n = int(input()) for i in range(n): i = input().strip() m = re.match(r'(.+)<(.+)>',i) if m: name = m.group(1).strip() email = m.group(2).strip() if re.match(pattern,email): print('{} <{}>'.format(name,email))
help me find the problem in my code because i have passed 6 out of 7 cases but this code is failing agaist test case 3 i don't know why even chat GPT could not help if anyone it would be quite appreciating and i will be obliged of him...
Here is HackerRank Validating and Parsing Email Addresses in Python solution - https://programmingoneonone.com/hackerrank-validating-and-parsing-email-addresses-solution-in-python.html