Validating and Parsing Email Addresses

Sort by

recency

|

338 Discussions

|

  • + 0 comments
    import re
    import email.utils
    
    total_emails = int(input())
    valid_email = r"^\<[a-zA-Z][\w\.\-]*@[a-zA-Z]+\.[a-zA-Z]{1,3}\>$"
    
    for _ in range(total_emails):
        name_email = input()
        if re.match(valid_email, name_email.split()[1]):
            print(email.utils.formataddr(email.utils.parseaddr(name_email)))
    
  • + 0 comments
    import re
    
    for i in range(int(input())):
        s = input().split()
        mail = re.search(r"<([A-Za-z][\w\.-]+)@([A-Za-z]+)\.([A-Za-z]{1,3})>", s[1])
        if mail:
            print(s[0], mail.group())
    
  • + 0 comments
    import re
    import email.utils
    p = r'^[a-zA-Z][\w.-]+@[a-zA-Z]+\.[a-zA-Z]{1,3}$'
    for _ in range(int(input())):
        n, e = email.utils.parseaddr(input())
        if re.match(p, e):
            print(email.utils.formataddr((n, e)))
    
  • + 0 comments

    Can anyone help me out! Why showing error while submitting code, which works well in google colab. pattern = r"^[a-zA-Z0-9_.+-]+@[a-zA-Z0-9-]+.[a-zA-Z]{2,}$" import re import email.utils a = int(input()) for i in (input().splitlines()): name, user_email = email.utils.parseaddr(i) if re.match(pattern, user_email): print(email.utils.formataddr(i)) else: pass

  • + 0 comments

    import re, email.utils

    for _ in range(int(input())): name, address = input().split() if re.match('[a-z][\w\-\.]+@[a-z]+.[a-z]{1,3}$', address): print(email.utils.formataddr(email.utils.parseaddr((name, address.strip('<>'))))) else: pass