本页面有中文版。
Cette page est disponible en français.
Esta página está disponible en español.
Patterns1 live hunt inside

Email regex: copy-ready patterns that actually work

Three copy-ready email regex patterns (simple, practical and strict), when to use each, and the common mistakes that reject real addresses.

Regex Hunter logo

· 5 min read · Updated

/^[^\s@]+@[^\s@]+\.[^\s@]+$/

match

  • ana@site.com
  • x+t@site.io
  • jo@mail.co.uk

spare

  • ana@example
  • @site.com
  • a@@b.io

01Copy-ready email regex

Pattern Use it when
^\S+@\S+$ Simple. A quick sanity check, such as filtering logs or a search box.
^[^\s@]+@[^\s@]+\.[^\s@]+$ Practical (our pick). Sign-up and contact forms: every real address passes, common typos don't.
^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$ Strict. You need to accept exactly what a browser's type="email" field accepts.

Try any of them on your own addresses in the Playground, or practise on the Format validators pack. The rest of this post explains why the practical one is the right default.

Search for "email regex" and you'll find patterns of every size, from ten characters to several thousand. People have tried to encode the full email standard in one regular expression, and the results are famously unreadable.

The good news: you don't need any of that. Below are the pattern we recommend, why stricter patterns cause more trouble than they prevent, and what to do instead. Every example is live, so edit the patterns and see what changes.

02Why a "perfect" email regex doesn't exist

The email address format allows far more than most people expect. All of these are valid:

  • x+newsletter@site.io (a plus tag, used to filter mail)
  • j.doe@mail.co.uk (a subdomain and a two-part country ending)
  • ana@studio.photography (a long top-level domain)
  • josé@exemplo.com.br (non-English letters, supported by mail servers that handle international addresses)

And a pattern can't tell you whether an address exists. ana@example.com has a perfect shape and still might bounce. The only real check is sending a message and asking the person to click a link.

So the job of a regex is smaller than it looks: catch obvious typos before you send that message.

03The pattern we recommend

Matches9/9 as expected
/^[^\s@]+@[^\s@]+\.[^\s@]+$/

Should match5/5

  • ana@example.com
  • j.doe@mail.co.uk
  • x+tag@site.io
  • ana@studio.photography
  • josé@exemplo.com.br

Should not4/4

  • ana@example
  • ana@@example.com
  • ana @example.com
  • @example.com
Try it in the Playground
Something without spaces or @, then one @, then a domain with at least one dot. Every real-world address passes, and the common typos don't.

Read it in four parts:

  1. ^[^\s@]+ one or more characters that aren't whitespace or @
  2. @ exactly one at sign
  3. [^\s@]+\. a domain name, then a literal dot
  4. [^\s@]+$ the rest of the domain, to the end

It's short, it's readable, and it doesn't reject anyone with a real address.

04Mistake 1: forgetting the anchors

Without ^ and $, a regex only needs to find an email-shaped piece somewhere in the text:

Matches2/2 as expected
/\S+@\S+/
  • ana@example.com
  • not an email: a@b c
Try it in the Playground
The last line passes because "a@b" appears inside it. With ^ and $ the whole input has to be the address.

05Mistake 2: being too strict

The most common email patterns online look like this one. It seems careful, and it locks out real people:

Matches4/4 as expected
/^[\w.]+@\w+\.[a-z]{2,4}$/

Should match1/1

  • ana@example.com

Should not3/3

  • j.doe@mail.co.uk
  • x+tag@site.io
  • ana@studio.photography
Try it in the Playground
Every line here is a valid address, and this pattern accepts only the first.

It fails three ways at once:

  • \w+ before the dot allows only one domain part, so mail.co.uk fails.
  • [\w.] has no +, so plus-tagged addresses fail.
  • [a-z]{2,4} assumes top-level domains are short. Hundreds are longer: .photography, .software, .museum.

Even a more careful version, ^[\w.+-]+@[\w-]+(\.[\w-]+)+$, still rejects josé@exemplo.com.br, because \w only covers English letters in most engines. A rejected real address is a lost signup. A typo that slips through gets caught by the confirmation email anyway.

06What browsers use

HTML's <input type="email"> checks addresses with its own pattern, published in the HTML standard:

Pattern133 chars
/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/
Try it in the Playground
The HTML standard's pattern. It allows user@localhost (no dot needed) and rejects non-English letters before the @.

If you use type="email" on a form, the browser already runs this check for you. That's usually enough for the front end.

07A regex golf version

Validation and golf have different goals. A validator has to be safe on any input. A golf board only has to separate these words, so you can look at the smallest difference.

Every monster below has a letter right before the @ and a dot somewhere after it. Each innocent breaks one of those rules:

Live huntpar 8

Catch the email-looking strings, spare the broken ones.

Targets · 0/4 caught

  • ana@site.comtarget
  • bo@mail.iotarget
  • x.y@z.orgtarget
  • k@q.devtarget

Innocents · 0 hit

  • ana@siteinnocent
  • @mail.ioinnocent
  • bo@@z.orginnocent
  • site.cominnocent
  • a.b@cinnocent

Type a regex — the board updates as you go.

Try it in the Playground
Like this? A new one drops every day.Play today’s hunt

08Checklist

  • Use ^[^\s@]+@[^\s@]+\.[^\s@]+$ or the browser's type="email".
  • Always anchor with ^ and $ when validating a whole input.
  • Don't limit top-level domains to 2 to 4 letters.
  • Don't reject +, extra dots in the domain, or non-English letters.
  • Send a confirmation email. It's the only test that proves the address works.

09Keep practising