Email Address Validation
Match and validate email addresses in the standard user@domain.tld format.
Try it in RegexPro →Available in
JavaScript / ECMAScript code
const re = new RegExp("[a-zA-Z0-9._%+\\-]+@[a-zA-Z0-9.\\-]+\\.[a-zA-Z]{2,}", "g");
const input = "user@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.\-]+\.[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+.
Go (RE2) code
package main
import (
"fmt"
"regexp"
)
func main() {
re := regexp.MustCompile(`[a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}`)
input := `user@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.\-]+\.[a-zA-Z]{2,} (flags: g)Raw source: [a-zA-Z0-9._%+\-]+@[a-zA-Z0-9.\-]+\.[a-zA-Z]{2,}
How it works
Examples
Input
user@example.comMatches
user@example.com
Input
hello.world+tag@sub.domain.orgMatches
hello.world+tag@sub.domain.org
Input
invalid-emailNo match
—Common use cases
- •Form input validation
- •Extracting emails from plain text
- •Filtering and de-duplicating contact lists
- •Log file analysis for email activity
Related patterns
Email Domain Part (After @)
ValidationValidate just the domain portion of an email address — the bit after the @.
Email Local Part (Before @)
ValidationValidate just the local part of an email address (the bit before the @).
Cron Expression
ValidationValidate standard 5-field Unix cron expressions: minute, hour, day-of-month, month, day-of-week.
International Phone (E.164)
ValidationValidate phone numbers in ITU-T E.164 international format: a + sign followed by 2–15 digits, first digit non-zero.
Related concepts
Character Classes: \d, \w, \s and Their Negations
ConceptShorthand character classes match broad categories of characters. \d is a digit, \w is a word character, \s is whitespace. Uppercase negates.
Quantifiers: *, +, ?, and {n,m}
ConceptQuantifiers repeat the preceding element. * is 0 or more, + is 1 or more, ? is 0 or 1. {n}, {n,}, and {n,m} give exact counts and ranges.
How to Validate an Email with Regex
How-toUse a pragmatic regex for structural validation, then confirm deliverability separately. Full RFC 5322 compliance is overkill and error-prone.