Token-by-token breakdown
| Token | Meaning | Example |
|---|---|---|
^ |
Anchor: asserts position at start of the string | Start of 'user@example.com' |
[a-zA-Z0-9._%+-] |
Character class: matches any single alphanumeric character, dot, underscore, percent, plus, or hyphen | 'u', 's', 'e', '.', '_', '%', '+', '-' |
+ |
Quantifier: matches one or more of the preceding token (greedy) | Matches one or more characters in 'user123' |
@ |
Literal character: matches the @ symbol literally | '@' |
[a-zA-Z0-9.-] |
Character class: matches any single alphanumeric character, dot, or hyphen | 'e', 'x', 'a', '.', '-' |
+ |
Quantifier: matches one or more of the preceding token (greedy) | Matches one or more characters in 'example' |
\. |
Escaped literal: matches a literal dot (.) character | '.' |
[a-zA-Z] |
Character class: matches any single alphabetic character (case-insensitive) | 'c', 'o', 'm' |
{2,} |
Quantifier: matches 2 or more of the preceding token (greedy) | Matches 'com' in 'example.com' |
$ |
Anchor: asserts position at end of the string | End of 'user@example.com' |
Matches
user@example.comjohn.doe123@sub.domain.coa@b.ctest_email+filter@domain.org123.456@789.xyz
Does not match
user@.com@example.comuser@example..comuser@example.cuser@example.com.user@-example.comuser@example_com
Common pitfalls
- Fails to validate internationalized email addresses (non-ASCII characters)
- Does not enforce length limits on the local part or domain
- Allows consecutive dots in the local part (e.g., 'user..name@example.com')
- Does not validate domain labels (e.g., 'example..com')
- Does not handle quoted strings in the local part (e.g., '"user name"@example.com')
Performance notes
The pattern is efficient for typical email validation as it uses simple character classes and quantifiers. No catastrophic backtracking risk due to the absence of nested quantifiers or alternations. Anchors ensure the entire string is validated, preventing partial matches.