Validating and Parsing Email Addresses

  • + 0 comments

    BTW, if you want to do it with regex, this is one way:

    import re
    
    for _ in range(int(input())):
        r_in = r"^([a-zA-Z]+) <([a-zA-Z][\w.-]+)@([a-zA-Z]+)\.([a-z]{1,3})>$"
        found = re.match(r_in, input())
        if found:
            name, username, domain, ext = found.group(1), found.group(2), found.group(3), found.group(4)
            print(f'{name} <{username}@{domain}.{ext}>')