Regex tester

Type a regular expression and some text to see every match highlighted, each capture group in a table, and what a replace would produce.

  • 100% free
  • Runs in your browser
  • No uploads
Matches

Uses your browser's own JavaScript regex engine, in a background worker that is stopped if a pattern runs too long.

How to test a regex

  1. Type the pattern. Without the slashes. Pasting a whole /pattern/flags literal splits it for you.
  2. Set the flags. g finds every match, i ignores case, m makes ^ and $ work per line, s lets . match line breaks.
  3. Paste your test text. Matches are highlighted as you type and listed with their position and groups.
  4. Preview a replacement. Tick Replace matches and type the replacement, using $1 or $<name> for groups.

Regex cheat sheet

PatternMatches
.Any character except a line break (any at all with the s flag)
\d \w \sA digit, a word character (letter, digit, _), a whitespace character
\D \W \SThe opposite of each of the above
[abc] [^abc] [a-z]One of a, b or c; anything but those; a range
^ $Start and end of the text (of each line with m)
\bA word boundary
* + ?0 or more, 1 or more, 0 or 1
{3} {2,5} {2,}Exactly 3, between 2 and 5, 2 or more
*? +?Lazy: as few as possible
(…) (?:…) (?<name>…)Capture group, group that doesn't capture, named group
a|ba or b
(?=…) (?!…) (?<=…) (?<!…)Followed by, not followed by, preceded by, not preceded by
\1 \k<name>The same text a group matched earlier

Useful patterns

  • A date like 2024-03-15: \b(\d{4})-(\d{2})-(\d{2})\b. Swap to 15/03/2024 by replacing with $3/$2/$1.
  • A simple email check: ^[^\s@]+@[^\s@]+\.[^\s@]+$. Real address rules are far looser; send a confirmation email rather than rejecting unusual addresses.
  • Doubled words: \b(\w+)\s+\1\b with the i flag finds "the the".
  • Trailing spaces: [ \t]+$ with g and m, replaced with nothing.

Common mistakes

  • Forgetting to escape. . ? + ( and [ are special; to match a real dot, write \..
  • Greedy .* eating too much. <.*> matches from the first < to the last > on the line. Use <.*?> or <[^>]*>.
  • Double escaping in code. In a JavaScript string, "\\d" is needed to get \d. Here, type the pattern as it appears between slashes.

Frequently asked questions

Which regex flavour does this use?

JavaScript (ECMAScript), using your browser's own engine, so a pattern that works here works the same in JavaScript and TypeScript code in that browser. Most syntax is shared with PCRE, Python and Java, but some isn't: possessive quantifiers, atomic groups and \A or \Z anchors are not JavaScript.

Why does my pattern only find the first match?

Without the g (global) flag, a JavaScript regex stops at the first match. Tick g to find every match. The same applies to replace: without g only the first match is replaced.

What does "stopped after 2 seconds" mean?

The pattern took too long, usually because of catastrophic backtracking: nested repeats such as (a+)+, (.*)* or (\w+\s?)+ can try an exponential number of ways to match text that almost matches. The test runs in a background worker that's stopped after 2 seconds, so the page stays usable. Make the inner part more specific or remove one level of repetition.

How do I use groups in the replacement?

$1, $2 and so on insert numbered groups, $<name> inserts a named group, $& inserts the whole match and $$ inserts a dollar sign. For example, (\w+)@(\w+) with $2: $1 turns ada@example into example: ada.

Is my text sent anywhere?

No. The regex runs in your browser, so it is safe to test against logs, customer data or anything else you can't share.