Python (re)

Email Local Part (Before @) in PY

Validate just the local part of an email address (the bit before the @).

Try it in the PY tester →

Pattern

regexPY
^[a-zA-Z0-9._%+\-]{1,64}$

Python (re) code

pyPython
import re

pattern = re.compile(r"^[a-zA-Z0-9._%+\-]{1,64}$")
input_text = "john.doe"
for m in pattern.finditer(input_text):
    print(m.group(0))

Stdlib `re` module — no third-party dependency. Works on Python 3.6+.

How the pattern works

^ and $ anchor to the full string. [a-zA-Z0-9._%+\-] is the conservative local-part character set (dots, underscores, percent, plus, hyphen for sub-addressing). {1,64} enforces the RFC max length for the local part.

Examples

Input

john.doe

Matches

  • john.doe

Input

user+tag

Matches

  • user+tag

Input

has space

No match

Same pattern, other engines

← Back to Email Local Part (Before @) overview (all engines)