Regex Tester & Explainer

Build and debug regular expressions with live highlighting, capture groups, replace and split. Every part of your pattern is explained in plain English, and runaway patterns are stopped before they freeze your browser.

Loading…

Test text

Matches

Each match with its position and what every capture group picked up.

What this pattern means

Quick reference

  • . any character, \d a digit, \w a letter, digit or underscore, \s whitespace. Capitals mean the opposite: \D is anything but a digit.
  • [abc] one of a, b or c; [^abc] anything else; [a-z] a range.
  • * zero or more, + one or more, ? optional, {2,5} two to five times. Add ? after any of these to match as little as possible.
  • ^ and $ are the start and end (of each line with the m flag). \b is the edge of a word.
  • ( ) captures a part, (?: ) groups without capturing, (?<name> ) names the group, and a|b means a or b.
  • To match a special character literally, put a backslash before it: \. \( \$.

JavaScript compared with other languages

  • This tester uses your browser's own JavaScript engine, so results match what your JavaScript or TypeScript code will do.
  • PHP (PCRE): also has possessive quantifiers (a++), atomic groups ((?> )), recursion and \A, \z. In JavaScript, $ without the m flag only matches at the very end, not before a final line break.
  • Python: names groups with (?P<name> ), uses \1 or \g<name> in replacements, and only allows fixed-length lookbehind. JavaScript allows any length.
  • .NET: adds balancing groups and RegexOptions, and uses ${name} in replacements where JavaScript uses $<name>.
  • Simple patterns usually work the same everywhere. Test advanced features in the language you'll use.
What is catastrophic backtracking?

When a pattern can match the same text in many different ways, such as (a+)+, the engine may try every combination before it gives up. On text that almost matches, that can take years. It's a real security risk on servers (called ReDoS). This tester runs your pattern in a separate background worker and stops it after a couple of seconds, so your browser never freezes.

Is my text sent anywhere?

No. The pattern and test text stay in your browser. Nothing is uploaded or saved.

Can a regex fully validate an email address or postcode?

Only the format. A regex can't tell you whether a postcode, phone number or email address actually exists. Use it to catch typos, then confirm in other ways, for example by sending a confirmation email.