Regex Tester

Live matching, capture groups and a replacement preview for JavaScript regex.

Flags

A regex tester is only useful if it shows the same engine the code will use. This one runs JavaScript's own RegExp, so what matches here matches in Node and in the browser — and what fails here fails there, with the same error message rather than an approximate one.

The capture group table is the part that saves time. Reading groups out of a highlighted match is guesswork once nesting appears; seeing `$1` and `$2` resolved side by side is how you find the off-by-one that put the area code in the wrong group.

How to use it

  1. Type the pattern without the surrounding slashes. Flags are separate checkboxes.
  2. Paste your sample text. Matches are highlighted as you type, and the count appears next to the pattern label.
  3. Add a replacement string with $1, $2 references to preview the substitution before you put it in code.

The one risk this page cannot remove

Catastrophic backtracking is a property of the pattern, not of the tester. A pattern like (a+)+$ against a long string of a's can take exponential time, and because JavaScript regex runs on the main thread, the tab freezes while it does. No browser API allows interrupting it.

The practical defence is to know the shapes that cause it: nested quantifiers over the same character class, alternation inside a repeated group, and unbounded repetition followed by something that can also match the same text. Rewriting (a+)+ as a+ is the usual fix, and possessive quantifiers — which JavaScript lacks — are why some patterns that work in PCRE hang here.

Reviewed 2026-10-26. This tool runs entirely in your browser — no server, no account, and nothing you generate is stored.

Frequently asked questions

Which regex flavour is this?

JavaScript (ECMAScript) RegExp, the same engine used in browsers and Node. Lookbehind is supported in modern engines; possessive quantifiers and atomic groups are not, so a pattern copied from PCRE may fail here.

Why did my pattern freeze the page?

Catastrophic backtracking — nested quantifiers that make the engine try an exponential number of paths. Reload the tab and simplify the pattern; the browser offers no way to time out a regex.

How do I match across multiple lines?

Enable the m flag for ^ and $ to match at line boundaries, and the s flag for . to match newlines. Without s, a dot stops at the end of the first line, which is the most common surprise.

What does an empty match mean?

The pattern can match zero characters at that position — for example a* on text without any a. The tester advances one character after an empty match so the loop terminates, which is what String.replace does internally.

Related tools

More from Device tests.