Validating and Parsing Email Addresses

Sort by

recency

|

340 Discussions

|

  • + 0 comments

    Whitout email.utils -->

    import sys, re
    
    text = sys.stdin.read().splitlines()[1:]
    
    match_pattern = re.compile(
        r"^[a-z]+\s"
        r"<[a-z](\w|[.-])*[@][a-z]+[.][a-z]{1,3}>"
    , re.I)
    
    match_list = [re.search(match_pattern, line) for line in text]
    
    for match in match_list:
        if match: sys.stdout.write(f'{match.group()}\n')
    
  • + 0 comments
    import re 
    import email.utils as email 
    
    n = int(input())
    
    r = re.compile(r'^[a-z](\w|-|\.)*@[a-z]+\.[a-z]{1,3}$')
    
    for i in range(n):
        name,mail = email.parseaddr(input())
        
        if r.match(mail):
            print(email.formataddr((name,mail)))
    
  • + 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)))