Token-by-token breakdown
| Token | Meaning | Example |
|---|---|---|
^ |
Anchor: asserts the position at the start of the string | Start of string |
[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+ |
Character class matching one or more allowed characters in the local part of the email (before @), including letters, digits, and special characters | user.name+tag |
@ |
Literal @ symbol separating local part and domain | @ |
[a-zA-Z0-9] |
Character class matching a single alphanumeric character for the start of the domain part | e |
(?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])? |
Non-capturing group for domain labels (max 63 chars, alphanumeric with hyphens allowed but not at start/end), optional | example |
(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)* |
Non-capturing group for subdomains and top-level domains, allowing zero or more occurrences of a dot followed by a domain label | .com,.co.uk |
$ |
Anchor: asserts the position at the end of the string | End of string |
Matches
user@example.comfirst.last@sub.domain.co.ukemail+tag@domain.orguser_name@domain.neta@b.c
Does not match
user@.comuser@domain..com@domain.comuser@domainuser@domain.cuser@domain..comuser@-domain.comuser@domain-.com
Common pitfalls
- Does not validate internationalized domain names (IDNs) or quoted strings in the local part
- Does not enforce maximum total length of the email address (RFC 5321 recommends 254 chars)
- Overly permissive with special characters in the local part that may not be accepted by all email providers
- Does not check for consecutive dots in the local part or domain
- Does not handle IP addresses in the domain part (e.g., user@[192.168.1.1])
Performance notes
The pattern is generally efficient due to the use of non-capturing groups and quantifiers with bounded repetition. However, very long domain labels (close to 63 characters) could lead to excessive backtracking in pathological cases. Anchoring at both start and end ensures the regex matches the entire string, preventing partial matches.