Email Domain Part (After @)
Validate just the domain portion of an email address — the bit after the @.
Try it in RegexPro →Available in
JavaScript / ECMAScript code
const re = new RegExp("^[a-zA-Z0-9](?:[a-zA-Z0-9.\\-]{0,253}[a-zA-Z0-9])?\\.[a-zA-Z]{2,24}$", "");
const input = "example.com";
const matches = [...input.matchAll(re)];
console.log(matches.map(m => m[0]));Uses `String.prototype.matchAll` for global iteration (Node 12+ / all modern browsers).
Python (re) code
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+.
Go (RE2) code
package main
import (
"fmt"
"regexp"
)
func main() {
re := regexp.MustCompile(`^[a-zA-Z0-9](?:[a-zA-Z0-9.\-]{0,253}[a-zA-Z0-9])?\.[a-zA-Z]{2,24}$`)
input := `example.com`
for _, match := range re.FindAllString(input, -1) {
fmt.Println(match)
}
}Uses `regexp.MustCompile` (panics on bad patterns at startup) and `FindAllString` for all matches.
Pattern
^[a-zA-Z0-9](?:[a-zA-Z0-9.\-]{0,253}[a-zA-Z0-9])?\.[a-zA-Z]{2,24}$Raw source: ^[a-zA-Z0-9](?:[a-zA-Z0-9.\-]{0,253}[a-zA-Z0-9])?\.[a-zA-Z]{2,24}$
How it works
Examples
Input
example.comMatches
example.com
Input
mail.sub.domain.orgMatches
mail.sub.domain.org
Input
no-tldNo match
—Common use cases
- •Splitting an email and re-validating each half independently
- •Enterprise allowlists (only @company.com)
- •Domain-level analytics on mailing lists
- •Custom-domain validation in SaaS sign-up
Related patterns
Email Local Part (Before @)
ValidationValidate just the local part of an email address (the bit before the @).
Email Address Validation
ValidationMatch and validate email addresses in the standard user@domain.tld format.
BCP 47 Language Tag
ValidationValidate BCP 47 language tags like `en`, `en-US`, `zh-Hant-TW`, or `pt-BR`.
Cron Expression
ValidationValidate standard 5-field Unix cron expressions: minute, hour, day-of-month, month, day-of-week.