RegexBuilder · regex answers
Regex for an email address
/^[^\s@]+@[^\s@.]+(\.[^\s@.]+)+$/
There is no regex that accepts exactly the addresses RFC 5322 allows and rejects the rest — the grammar permits quoted strings, comments and nested parentheses. What you actually want is a shape check that rejects typos before you send mail. This one requires a local part, a single @, and a dotted domain, and nothing else decides deliverability. Send a confirmation message; that is the only real validation.
What each part does
| [^\s@]+ | one or more characters that are neither whitespace nor @ — the local part |
| @ | exactly one at-sign, because the class above forbids a second one |
| [^\s@.]+ | a domain label with no dots inside it |
| (\.[^\s@.]+)+ | one or more dot-plus-label groups, so the domain must contain at least one dot |
Tested against real input
Every row below was run through the engine when this page was built. The third column is the substring the pattern actually matched.
| Input | Result | Matched |
|---|---|---|
| [email protected] | matches | [email protected] |
| [email protected] | matches | [email protected] |
| [email protected] | matches | [email protected] |
| ada@example | no match | — |
| ada@@example.com | no match | — |
| ada @example.com | no match | — |
| @example.com | no match | — |
| [email protected] | no match | — |
The mistake to avoid
Copying a 6 000-character RFC 5322 monster off a forum. It is slower, it still rejects valid addresses, and it hides the fact that only a confirmation email proves the address exists.
Try it on your own text
Paste this pattern and your input, see each match highlighted with its capture groups, step through what the engine did, and get the equivalent syntax for JavaScript, Python, Java, Go and PCRE.
Open RegexBuilderOther regex answers
- Regex for a US phone number
- Regex for an IPv4 address
- Regex for a URL
- Regex for a date in YYYY-MM-DD format
- Regex to match digits only
- Regex for alphanumeric characters
- Regex to find special characters
- Regex for a strong password
- Regex to match whitespace
- Regex to trim leading and trailing whitespace
- Regex for a UUID
- Regex for a hex colour code