
Regex tester and explainer (JavaScript)
Type a pattern and some text: matches are highlighted as you type, with every group listed, a replace preview, and an explanation of each part of the pattern in plain English.
Runs in your browser. Pasted data never leaves it.
Character classes
.- any character except a line break
\d \w \s- digit, word character, whitespace (capital letter = opposite)
[abc] [^abc] [a-z]- one of, none of, a range
\p{L}- any letter (needs the u flag)
Quantifiers
* + ?- 0 or more, 1 or more, 0 or 1
{3} {2,5} {2,}- exactly 3, 2 to 5, 2 or more
*? +? ??- lazy: as few as possible
Anchors and groups
^ $- start and end of the text (of each line with m)
\b \B- word boundary, not a word boundary
(abc) (?:abc)- capturing group, non-capturing
(?<name>abc) \k<name>- named group and a backreference to it
a|b- a or b
(?=x) (?!x) (?<=x) (?<!x)- lookahead, negative lookahead, lookbehind, negative lookbehind
How to use it
- Type your pattern in the top box (without the slashes) and tick the flags you need.
- Type or paste your test text. Matches are highlighted in it as you type.
- Open Matches for each match's position and capture groups, Explain for a plain-English breakdown, and use the replace box to preview a substitution.
- Copy the pattern into your code as
/pattern/flags.
Questions
Which regex flavour is this?
JavaScript (ECMAScript), run by your browser's own engine, so it behaves exactly like new RegExp() in your browser or Node. Other flavours (PCRE, Python, Java, .NET) differ: for example, JavaScript has no possessive quantifiers, no atomic groups and no inline (?i) flags.
What do the flags do?
g find all matches, i ignore case, m ^ and $ match at every line, s the dot also matches line breaks, u full Unicode and \p{…}, y sticky, d record where each group matched. Hover or read the line under the pattern box.
Why does my page say the pattern took too long?
Some patterns can backtrack exponentially (catastrophic backtracking), such as (a+)+$ against a long string of a's ending in something else. The test runs in a separate worker that is stopped after about 1.5 seconds, so your tab never freezes. Rewrite the pattern to avoid nested quantifiers.
What do $1 and $<name> mean in the replacement?
$1 is the text of capture group 1, $<year> a named group, $& the whole match, $$ a dollar sign, and $` and $' the text before and after the match.
Is the explanation reliable?
It is generated from a parse of your pattern and describes each part in plain English. It covers all standard JavaScript syntax. If the pattern is invalid, you get the browser's own error message.
Is what I paste or test sent anywhere?
No. This page works entirely inside your browser, and pasted data never leaves your device. It makes no network requests while you use it, and the page also tells your browser to block them (a Content-Security-Policy with connect-src 'none'), so even a bug could not send your data out. To check it yourself, open your browser's developer tools, go to the Network tab, and use the tool: nothing will appear. There is no account, no analytics and no logging.
