Python (re)

Email Address Validation in PY

Match and validate email addresses in the standard user@domain.tld format.

Try it in the PY tester →

Pattern

regexPY
[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}   (flags: g)

Python (re) code

pyPython
import re

pattern = re.compile(r"[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}")
input_text = "user@example.com"
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

Matches a local part (letters, digits, dots, underscores, percent, plus, hyphen) followed by @, a domain name, a dot, and a TLD of at least 2 characters.

Examples

Input

user@example.com

Matches

  • user@example.com

Input

hello.world+tag@sub.domain.org

Matches

  • hello.world+tag@sub.domain.org

Input

invalid-email

No match

Same pattern, other engines

← Back to Email Address Validation overview (all engines)