// admin tools · 11
Regex bench
Live JavaScript RegExp matching with highlighted results, numbered and named groups, a replace preview and a token-by-token explanation. Runaway patterns are stopped after one second.
// runs locally — nothing is uploaded
$1–$99 numbered group · $<name> named group · $& whole match · $` before · $' after · $$ a literal $. Without the g flag only the first match is replaced.
How it works
What it does
This is a tester for JavaScript regular expressions, the same engine used by browsers, Node.js and Deno. As you type, matches are highlighted in the test string and listed with their index and capture groups. Separate tabs show a live replace preview, a plain-English breakdown of every token, and the pattern converted for Python, PHP and Go. All matching happens in your browser.
How to use it
- Type a pattern between the slashes. Toggle flags with the buttons on the right.
uandvare mutually exclusive. - Paste text into the test string. Matches alternate between two highlight colours so neighbours stay distinct. A thin bar marks a zero-length match, such as
^in multiline mode. - Use the chips to insert common tokens. They wrap any selected text, so selecting
abcand pressing(?:…)gives(?:abc). - Open --replace to preview
String.prototype.replace, or --explain to read the pattern token by token.
The pattern and flags are saved in the URL hash, so you can bookmark or share a link. The test string is not saved.
How the explainer and the safety net work
The explainer is a hand-written tokeniser that follows the ECMAScript grammar. It understands anchors, character classes and ranges, greedy and lazy quantifiers, capturing, named and non-capturing groups, lookahead and lookbehind, backreferences, inline flag modifiers, \p{…} Unicode property escapes and v-mode set operations. It also knows the legacy rules that apply without u, such as \1 being an octal escape when there is no group 1.
Some patterns backtrack exponentially. ^(a+)+$ against a long run of as followed by ! is the classic example (often called ReDoS). To stop this freezing the page, matching runs in a Web Worker. If it takes longer than one second, the worker is terminated and you get a warning instead. If workers are unavailable, matching falls back to the main thread with lower limits on input size and match count.
FAQ
Why does my pattern behave differently in Python or PHP?
Engines differ. Python's \d and \w match Unicode digits and letters by default, PCRE's $ also matches before a final newline, and Go's RE2 has no lookarounds or backreferences. The --code tab rewrites the syntax it can (for example (?<name>) becomes (?P<name>) in Python) and lists the behaviour differences it finds.
What does the g flag change?
Without g, only the first match is found and replaced, as with exec() or replace(). With g, every match is found. After an empty match the search moves forward one character, or one full code point with u or v.
Are my test strings sent anywhere?
No. The pattern and text are passed to a worker inside this page. Nothing is uploaded, logged or stored.