Validating and Parsing Email Addresses

Sort by

recency

|

357 Discussions

|

  • + 1 comment

    This was a very simple challenge. ~~Even without using email.utils, it would've been simple.~~

    Update: I changed my submission to not use email.utils, just to be shorter and to depend on fewer modules. Basically, it's the simplest possible program to read all input lines and output only those that match a regex.

    import re, sys
    
    # I included support for "+" in the address.
    # I hate when email address validators don't allow it.
    # Note that this is only a regex exercise, not a real email
    # address validation.  The ONLY TRUE way to validate an
    # email address is to send a message to it and instruct the
    # recipient to respond.  When their response is received, ONLY
    # THEN can the email address be considered valid.
    
    print(''.join(l for l in sys.stdin.readlines()[1:]
      if re.search(r'<[a-z][\w.+-]*@[a-z]+\.[a-z]{1,3}>', l, re.I)))
    
  • + 1 comment

    how to solve this code

  • + 0 comments

    import re import email.utils

    pattern = r'^[a-zA-Z][\w.-]*@[a-zA-Z]+.[a-zA-Z]{1,3}$'

    n = int(input()) for _ in range(n): line = input() name, addr = email.utils.parseaddr(line) if re.fullmatch(pattern, addr): print(email.utils.formataddr((name, addr)))

  • + 0 comments

    import re pattern = r'^[a-zA-z][a-zA-Z0-9_.-]*@[a-z]+.[a-z]{1,3}$'

    n = int(input()) for i in range(n): i = input().strip() m = re.match(r'(.+)<(.+)>',i) if m: name = m.group(1).strip() email = m.group(2).strip() if re.match(pattern,email): print('{} <{}>'.format(name,email))

    help me find the problem in my code because i have passed 6 out of 7 cases but this code is failing agaist test case 3 i don't know why even chat GPT could not help if anyone it would be quite appreciating and i will be obliged of him...

  • + 0 comments

    Here is HackerRank Validating and Parsing Email Addresses in Python solution - https://programmingoneonone.com/hackerrank-validating-and-parsing-email-addresses-solution-in-python.html