JavaScript RegExp

Regex tester

Run a JavaScript regular expression against real text, see every match and capture group, and preview the replacement — with limits that stop a runaway pattern from freezing the page.

Flags

Up to 20,000 characters per run.

The pattern and the test text stay in this tab. Nothing is evaluated on a server, which also means the page tells you honestly that a pathological pattern can still stall your browser.

Short answer: type the pattern without slashes, tick the flags you need, paste the text and press Test pattern. Every match is highlighted and listed with its index and capture groups; a replacement string produces the exact outputString.replace would give you.

Why the test needs a button

Most regex testers run on every keystroke. That is pleasant until you type(a+)+b and the engine starts backtracking on a 20 KB string: the tab freezes and there is no way to interrupt it. Here the work starts when you ask for it, the text is capped, and the run time is reported so a pattern that needs 900 ms is visible before it reaches production.

What the columns mean

Replace previews are exact

The preview calls String.prototype.replace with your flags, so $1,$&, $<name> and $$ behave as documented. With the g flag every match is replaced; without it only the first. An empty replacement deletes the matches, which is a legitimate way to strip them.

A pattern that works here produces the same result in Node and in the browser, but not necessarily in Python, PHP or Go — those are different engines. Keep that in mind when you paste an expression into a server-side validator.

Regex testing questions

Which regular expression flavour is this?

JavaScript, exactly as your browser implements it — the same engine as String.prototype.match and RegExp. That means lookbehind, named groups, Unicode property escapes with the u flag, and the d flag for match indices all work. Python or PCRE-only syntax such as (?P<name>…) does not.

What do the flags do?

g finds every match instead of the first, i ignores case, m makes ^ and $ match each line, s lets . match newlines, u enables full Unicode mode, y anchors each match at lastIndex (sticky), and d adds start/end indices for each capture group.

Why does the page warn about catastrophic backtracking?

A pattern such as (a+)+$ can take exponential time on the wrong input, and JavaScript cannot interrupt a running regular expression. The input is capped at 20,000 characters and the test runs when you press the button rather than on every keystroke, but a pathological pattern can still stall the tab. No browser-based tester can promise otherwise.

Why is my match list empty when the pattern works elsewhere?

Usually the g flag: without it only the first match is returned, and with it the engine advances lastIndex. The other common cause is anchoring — ^ and $ only mean start and end of the whole string unless the m flag is set. Check the pattern against the highlighted preview to see what actually matched.

What does the replace preview use?

String.prototype.replace with your replacement string, so $1, $&, $<name> and $$ behave exactly as they do in code. An empty replacement deletes the matches. The preview is not a second implementation — it is the same engine your application will run.

Related tools