Regex Patterns

Search for what you want to match, such as "email", "date" or "ip". Each pattern lists its flags, examples it matches and examples it refuses, and what it does not check.

How it works

A regular expression describes a shape of text. ^ and $ pin it to the start and end, \d is a digit, [a-z] is one letter from a range, and {2,4} means "two to four of the previous thing". Every pattern here is built from those few pieces.

Each pattern on this page is run by an automated test against the examples shown on its card: every "matches" example must match and every "does not match" example must not. If a pattern changed and broke an example, the page would not be published.

Patterns are written for JavaScript and copied without the slashes, ready for new RegExp(pattern, flags). Most work unchanged in Python, Java, PHP and C#. Lookaheads, used by the password pattern, do not work in Go.

How to use it

  1. 1 Type what you need to match, such as "postcode" or "uuid".
  2. 2 Read the card: the flags, the examples, and the note on what the pattern does not check.
  3. 3 Press Copy to copy the pattern.
  4. 4 Paste it into your code with the flags shown, then try it on your own data before relying on it.

Good to know

  • In a JavaScript string, every backslash must be doubled: "\\d" in a string is \d in the pattern. Using a /regex/ literal avoids that.
  • A pattern with the g flag remembers where it stopped, so calling .test() twice on the same text can give true, then false. Drop g for yes-or-no checks.
  • Validation patterns use ^ and $. Clean-up patterns, such as trailing spaces, use the g and m flags to find every match on every line.
  • For URLs, emails and dates, a regex checks the shape only. Parse the value, or send the email, to know it is real.

Browser support

  • Chrome 94 and later
  • Firefox 93 and later
  • Safari 16.4 and later
  • Edge 94 and later

These are the oldest versions with everything the tool uses. They are worked out from the tool itself, so they change when it does.

Version numbers checked on 2026-09-04.

Reading the date pattern piece by piece, and where it stops

A regular expression looks like noise until you read it one piece at a time. Take the date pattern from this page: ^\d{4}-(?:0[1-9]|1[0-2])-(?:0[1-9]|[12]\d|3[01])$. It is meant to accept a date written the ISO way, such as 2026-12-04, and refuse anything else. Here is how it gets there, and where it gives up.

The ^ says the match must start at the very beginning of the text, and the $ at the end says it must finish at the very end. Without them, the pattern would happily find a date inside "abc2026-12-04xyz". Next, \d{4} is any four digits, the year. Then a literal hyphen. The month is (?:0[1-9]|1[0-2]): the (?: ) groups two choices without capturing them, and the | means "or". So the month is either 0 followed by 1 to 9, which covers 01 to 09, or 1 followed by 0 to 2, which covers 10 to 12.

Now try it by hand on "2026-13-01". The year 2026 matches \d{4}, and the hyphen matches. For the month, 13 starts with 1, so the first choice, which needs a 0, fails. The second choice needs 1 then 0, 1 or 2, and 3 is none of those, so it fails too. The whole pattern fails, which is what we want. For "2026-12-04", the month 12 matches 1[0-2], and the day 04 matches 0[1-9]. The day part, (?:0[1-9]|[12]\d|3[01]), works the same way: 01 to 09, then 10 to 29, then 30 or 31.

Now try "2026-02-30". The month 02 matches, and the day 30 matches 3[01]. The pattern says yes, but there is no 30 February. This is not a bug that a cleverer regex should fix. A pattern that knows month lengths, and leap years on top, is possible but long and hard to check. The honest design is to let the regex confirm the shape, then hand the value to a real date parser that knows the calendar. Every card on this page has a line like this, saying what its pattern leaves for code to check.

That is the main limit of a pattern library. These patterns are tested against the examples on their cards, but your data will contain cases no example list predicted, so run a pattern on real samples before trusting it. Some are deliberately simplified, and say so: the IPv6 pattern skips zone suffixes and embedded IPv4, and the UK postcode pattern allows a few combinations Royal Mail never issues. And a few jobs should not be done with a regex at all, such as removing HTML tags for safety, where a real parser is the right tool.

Frequently asked questions

Why not use the full RFC 5322 email regex?

Because it accepts addresses no real mail system hands out, such as quoted names with spaces, and it still cannot tell whether a mailbox exists. A simple pattern catches typos; sending a confirmation email is the only real check.

Why does my pattern work here but not in my code?

Usually backslashes. Written inside a string, \d must be typed as "\\d", or the string eats the backslash. The other common cause is a missing flag, such as i for ignoring case or m for matching each line.

Can I validate a date with a regex?

Only its shape. The date pattern here refuses month 13 but allows 2026-02-30, because knowing month lengths and leap years needs arithmetic. Check the shape with the regex, then parse the date and compare.

Do these patterns work in Python?

Almost all of them, with re.search or re.fullmatch. Pass re.IGNORECASE for the i flag and re.MULTILINE for m. Python has no g flag; use re.findall or re.sub to act on every match.

Related tools

Your files are processed on your device and are not uploaded. You can verify this in your browser’s developer tools under the Network tab.