This Python program is designed to validate and parse email addresses. It takes a number of email addresses as input and checks each one to see if it matches a specific pattern. If the email address is valid, it is printed out.
CodeRankGPT is a tool powered by GPT-4 that quietly assists you during your coding interview, providing the solutions you need.
In real-time and absolutely undetectable 🥷
The solution works by using the 'email.utils' and 're' modules in Python. The 'email.utils' module is used to parse the email address, and the 're' module is used to match the parsed email against a regular expression pattern. The pattern checks if the email starts with an alphabet character, followed by any combination of alphabets, numbers, periods, underscores, and hyphens. This is followed by an '@' symbol, then another set of alphabets, a period, and finally 1 to 3 alphabet characters. If the email matches this pattern, it is considered valid and is printed out.
import email.utils
import re
n = int(input())
for _ in range(n):
s = input()
parsed_email = email.utils.parseaddr(s)[1].strip()
match_result = bool(
re.match(
r"(^[A-Za-z][A-Za-z0-9\._-]+)@([A-Za-z]+)\.([A-Za-z]{1,3})$", parsed_email
)
)
if match_result:
print(s)
If you have a HackerRank coding test coming up, you can use CodeRankGPT to your advantage. It will assist you during your interview and help ensure you get the job.
AI is here now, and other candidates might be using it to get ahead and win the job. 🧐
The form has been successfully submitted.