# Without Using VERBOSE
regex_email = re.compile(r'^([a-z0-0_\\\\.-]+)\\.([a-z\\.]{2,6})$',
       re.IGNORECASE) 

# Using VERBOSE
regex_email = re.compile(r"""
      ^([a-z0-9_\\.-]+)            # local part
       @             # single @ sign
       ([0-9a-z\\.-]+)       # Domain name
       \\.            # single Dot .
       ([a-z](2,6))$        # Top level Domaim
       """,re.VERBOSE | re.IGNORECASE)

It will be forwarded as argument into re.compile() which re.compile(Regular Expression, re.VERBOSE) . re.compile() will return RegexObject which later will be matched with the string that is given.

Let’s we consider example where the user is requested to enter their email ID and we have to validate it using RegEx. The email format is attached below:

Input: [email protected]

Output: Valid

Input: [email protected]@

Output: Invalid invalid because there is @ after top-level domain name

Implementation