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
|
355 Discussions
|
Please Login in order to post a comment
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
import email.utils import re n =int(input()) pattern = re.compile(r'[a-zA-Z][\w.-]*@[a-zA-Z]+.[a-zA-Z]{1,3}$') for _ in range(n); line = input().strip() name, address = email.utils.parseaddr(line) if pattern.match(address): print(email.utils.formataddr((name, address)))
Wierd..
This code works fine on my laptop, but not here? Added regexp, but still why???
if name == 'main': email_count = int(input().strip()) to_validate = [input().strip() for _ in range(email_count)]