Validating and Parsing Email Addresses

  • + 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')