Skip to content
MoneyDeck

Regex Generator

Ready-made regex for email, phone, dates, IPs and more — explained

Updated · Free, no signup

Regular expression

[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}

Code snippet

const re = /[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}/g;
const matches = text.match(re) ?? [];

Matches / valid lines

2

Results on test text

[email protected]
[email protected]

What it does not catch

This practical pattern accepts almost all real addresses but not every form RFC 5322 allows (quoted local parts, IP-literal domains). The only reliable check is sending a confirmation email.
  • Showing results for the built-in sample text. Paste your own text to test it.

Pattern explained token by token

TokenMeaning
[A-Za-z0-9._%+-]+Local part: one or more letters, digits or . _ % + -
@A literal @ sign
[A-Za-z0-9.-]+Domain name: letters, digits, dots and hyphens
\.A literal dot before the top-level domain
[A-Za-z]{2,}Top-level domain of at least two letters (com, io, museum)

About the Regex Generator

This regex generator gives you a tested regular expression for the patterns developers need most — email addresses, URLs, US and international phone numbers, ISO and US dates, 24-hour times, IPv4 addresses, hex colours, ZIP and UK postcodes, UUIDs, slugs, usernames, strong passwords, semantic versions and decimal numbers. Each pattern comes with a token-by-token explanation and an honest note about what it does not catch.

Choose whether you want to find matches inside text or validate a whole value, switch on case-insensitive matching if needed, and pick your language: the tool writes a ready-to-paste snippet for JavaScript, Python, PHP, Java, C# or Go, escaping slashes, quotes and backslashes correctly for that language. Paste your own sample text to see exactly what the pattern matches before you ship it.

In validate mode the pattern is wrapped in ^(?: … )$ and each line of your test text is checked separately, which is how you would validate form fields. Regular expressions check format, not truth — a well-formed email may not exist and a date like 2026-02-31 passes the shape test — so pair them with real validation where it matters.

How to use the regex generator

  1. 1Pick the kind of value you need to match.
  2. 2Choose Find to extract matches from text, or Validate to check whole values.
  3. 3Select your programming language and copy the snippet.
  4. 4Paste real sample data into the test box and check every match.
  5. 5Read the caveat and add extra checks in code where the format alone is not enough.

Formula and method

find: /pattern/g validate: /^(?:pattern)$/

Each pattern is built from character classes such as [A-Za-z0-9] or \d (a digit), quantifiers like + (one or more), ? (optional) and {2,} (two or more), and non-capturing groups (?: … ) with alternation | for choices such as 0[1-9]|1[0-2] for months. Numeric ranges like 0–255 are spelled out digit by digit because regex compares characters, not numbers.

In find mode the pattern is run with the global flag and every non-overlapping match is listed. In validate mode it is wrapped in ^(?: … )$ so the whole line must match, and each line of the test text is checked on its own. The language snippet escapes the pattern for that language’s string or literal syntax; the pattern itself uses only syntax shared by JavaScript, PCRE, Python, Java and .NET (Go lacks lookaheads).

Worked examples

Extract email addresses from text

The email pattern finds two addresses. "user@localhost" has no dot-separated top-level domain and "@example.com" has no local part, so neither matches. The plus-addressed j.doe+news@… is accepted because + is allowed in the local part.

Validate a list of IPv4 addresses

Anchored with ^(?: … )$, each line must be exactly four octets from 0 to 255. 192.168.1.1 and 10.0.0.255 pass; 256.1.1.1 fails because 256 is out of range and 172.16.0 fails because it has only three octets.

ISO dates as a Python snippet

Two dates match. 2026-13-01 fails because months stop at 12, and 2026-9-5 fails because the month and day need two digits. The Python version uses a raw string r"…" so the backslashes in \d reach the regex engine unchanged.

Frequently asked questions

What is the best regex for email validation?+

A practical choice is [A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}. It accepts virtually all real addresses; fully RFC 5322-compliant patterns are enormous and still cannot tell whether a mailbox exists, so confirm addresses by sending an email.

How do I match a whole string instead of part of it?+

Anchor the pattern with ^ at the start and $ at the end, wrapped in a group if it contains alternation: ^(?:pattern)$. In Python you can use re.fullmatch, and in Java String.matches already requires the whole string to match.

Why does my regex work in JavaScript but not in Go?+

Go uses the RE2 engine, which guarantees linear-time matching by leaving out backreferences and lookarounds such as (?=…). Patterns that rely on them must be rewritten as several simpler checks in Go code.

Do I need to escape slashes in a regex?+

Only when the slash is also the literal delimiter, as in JavaScript /…/ literals or PHP preg patterns, where / becomes \/. In Python, Java or C# strings the slash needs no escaping, but backslashes may need doubling in non-raw strings.

Can a regex check that a date is real?+

Only partially. A regex can restrict months to 01–12 and days to 01–31, but it cannot easily know that February has 28 or 29 days. Match the format with the regex, then parse the date in code to confirm it exists.

Related tools