RRegexBuilder
Get RegexBuilder

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.

InputResultMatched
[email protected]matches[email protected]
[email protected]matches[email protected]
[email protected]matches[email protected]
ada@exampleno match
ada@@example.comno match
ada @example.comno match
@example.comno 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 RegexBuilder

Other regex answers