How to use it
- Type the regular expression without the slashes, and tick the flags you need.
- Paste the text to test it on; the matches are marked as you type.
- Read the groups of each match in the table below.
- Optionally type a replacement ($1, $<name>, $&) or show the split result, and copy it.
Rules and limits
How the pattern is run
- With the browser’s own RegExp object, so the result is what your JavaScript code will get. Flags: d (indices), g, i, m, s, u, v (Unicode sets, where the browser has it), y.
- Matches are found as
String.prototype.matchAllfinds them, and the replacement and split usereplaceandsplitthemselves. Checked in Node.js (the engine of Chrome) on 192 combinations of patterns, flags and texts: the same matches, groups, named groups, indices, replacements and parts. - The pattern runs in a separate worker. After 2 seconds the worker is stopped and the page says so: tested with (a+)+$ on forty “a” and a “b”, which would run for days.
- At most 10,000 matches are collected and 500 listed; texts of up to 5 MB.
Questions and answers
Will my regex work the same in Python, PHP or Java?
Often, but not always. Lookbehind, named-group syntax, Unicode classes and what \w or $ match differ between flavours. This page answers for JavaScript only, as browsers and Node.js run it.
Why did the page stop my pattern?
Some patterns, such as (a+)+$, try an exponential number of ways on text that almost matches. A server running such a pattern can hang. The page stops it after 2 seconds; rewrite the nested repeat as a single one (a+$).
What do $1, $<name> and $& mean in the replacement?
$1 is the text of the first group, $<name> of the group named name, $& the whole match; $ and $' are the text before and after it, and $$ is a dollar sign.
Is my text sent anywhere?
No. The pattern runs in your browser, and the page cannot send anything. Only the chosen flags are kept, for this tab.