Regexdrill

Patterns for common data Updated November 2026

Regex for email

A practical email regex is ^[^\s@]+@[^\s@]+\.[^\s@]+$ : one or more characters that are not whitespace or @, then @, a domain part, a dot and a top-level part. It catches typos without rejecting valid addresses. Full RFC 5322 validation is not worth a regex; confirm the address by sending a message.

Syntax

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

Examples

/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test("jane.doe@example.com")

Result: true

/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test("jane@localhost")

Result: false

There is no dot after the @. Drop the \. if you accept bare host names.

"Mail a@b.co or c.d@e-f.org".match(/[\w.+-]+@[\w-]+(?:\.[\w-]+)+/g)

Result: ["a@b.co", "c.d@e-f.org"]

Unanchored with the g flag to pull every address out of text.

/^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$/.test("first.last+tag@mail.example.co.uk")

Result: true

A stricter version that lists the allowed characters and requires a letters-only TLD.

Common mistakes

  • Using \w for the local part rejects jane.doe or news+tag; use [^\s@]+ or add . + and - to the class.
  • Forgetting ^ and $ lets x@y.z followed by garbage pass; anchor the pattern when validating a whole field.
  • Hardcoding \.(com|net|org)$ rejects newer domains; use \.[A-Za-z]{2,}$ instead.
  • Chasing an RFC-perfect pattern: the full RFC 5322 regex is thousands of characters and still cannot tell you if the mailbox exists.

Practice Regex for email

These drills check your answer on live data, free, no account needed.

  • Simple email addressesThe whole line must match. Use this simplified rule: a local part of letters, digits, dots, underscores, plus signs or hyphens; one @; one or more domain labels of letters, digits or hyphens separated by dots; and a final label of two or more letters.
  • Negated class: no vowelsThe whole line must match. Match lines that contain none of the lowercase vowels a, e, i, o or u. Any other characters are fine, including uppercase letters, digits and spaces.

Questions

Is there a perfect email regex?

No. The address grammar allows quoted local parts, comments and IP literals that no sane pattern covers, and a syntactically valid address can still bounce. Use a simple shape check, then verify by sending a confirmation email.

Should the email regex be case-insensitive?

The pattern above has no letter ranges, so case does not matter. If you use [a-z] ranges, add the i flag, because domains are case-insensitive and many mail servers treat local parts that way too.

How do I find all email addresses in a block of text?

Drop the anchors and add the g flag: text.match(/[\w.+-]+@[\w-]+(?:\.[\w-]+)+/g) returns an array of every address, or null when there are none.

Related

  • Regex for usernameUsername regex patterns: the basic ^[a-zA-Z0-9_]{3,16}$ rule, a stricter letter-first variant, pulling @handles out of text, and a Unicode-friendly version.
  • Regex for URLA URL regex for validation and for pulling links out of text, capturing scheme, host, port and path, avoiding trailing punctuation, and when to use new URL.
  • Negated character classHow [^...] matches any character except the listed ones, stripping non-digits, grabbing quoted text, splitting on a delimiter, and how it differs from (?!).
  • Regex for whitespaceHow \s matches spaces, tabs and newlines, trimming leading and trailing whitespace, collapsing repeated spaces, splitting on whitespace, and detecting blanks.

Next: Regex for phone number