Email Domain Part (After @) in PY
Validate just the domain portion of an email address — the bit after the @.
Try it in the PY tester →Pattern
regexPY
^[a-zA-Z0-9](?:[a-zA-Z0-9.\-]{0,253}[a-zA-Z0-9])?\.[a-zA-Z]{2,24}$Python (re) code
pyPython
import re
pattern = re.compile(r"^[a-zA-Z0-9](?:[a-zA-Z0-9.\-]{0,253}[a-zA-Z0-9])?\.[a-zA-Z]{2,24}$")
input_text = "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
Starts and ends with alphanumeric per RFC. Allows dots and hyphens in the middle. Length capped at 255 chars total. Trailing \.[a-zA-Z]{2,24}$ requires a TLD of 2–24 characters (covers everything from `.io` to `.international`).
Examples
Input
example.comMatches
example.com
Input
mail.sub.domain.orgMatches
mail.sub.domain.org
Input
no-tldNo match
—