TanodTools

Regex tester

Try a regular expression on sample text and see every match, its capture groups and the result of a replace.

Runs entirely in your browser

Flags

Matches in the text

  
#PositionMatchGroups

JavaScript (ECMAScript) regex syntax as your browser supports it. Text up to 5 MB; the first 1,000 matches are listed and highlighted. A pattern that runs longer than 2 seconds is stopped.

How to test a regular expression

  1. Type the pattern between the slashes and tick the flags you need, such as g for all matches or i to ignore case.
  2. Paste your test text. Matches are highlighted as you type, and the table lists each match with its position and capture groups.
  3. To check a substitution, type a replacement such as $2-$1 or $<year> and read the result below it.

Testing patterns safely

The tester builds a JavaScript RegExp from your pattern and flags and runs it in a background worker, the same engine your code will use in this browser. Matches come back with their start position and every capture group, and the page draws them over your text with alternating highlights so neighbouring matches stay distinguishable. An empty match, such as the one \b or a* can produce, shows as a thin bar.

Running the pattern in a worker matters because a regular expression can take exponential time. If a pattern is still running after 2 seconds, the worker is stopped and you get a message instead of a frozen tab. The same safeguard protects Find and replace.

Positions are counted in UTF-16 code units, which is how JavaScript strings count: an emoji or other character outside the basic plane takes two. The list shows the first 1,000 matches; the total count above it includes every match.

Tips

Questions

Which regex flavour does this use?

The JavaScript one, run by your own browser's engine, so the results are exactly what RegExp in your browser or Node.js gives. Most everyday syntax is shared with PCRE, Python and Java, but some features differ: possessive quantifiers and atomic groups are not supported, and lookbehind, named groups and the v flag need a current browser.

Why is only one match shown?

Without the g (global) flag, a JavaScript regex finds only the first match, and replace changes only the first occurrence. Tick g to find them all. The tester follows the language exactly so what you see is what your code will do.

What do the flags do?

g finds all matches, i ignores case, m makes ^ and $ match at line breaks, s lets . match line breaks, u turns on full Unicode handling, v is the newer Unicode mode with set operations, y (sticky) only matches at the current position, and d records the start of each group, which the tester uses for group positions anyway.

How do I use groups in the replacement?

$1, $2 and so on insert numbered groups, $<name> inserts a named group, $& inserts the whole match, $` and $' insert the text before and after it, and $$ writes a literal dollar sign.

Why did my pattern stop with "took too long"?

Some patterns, such as ^(a+)+$ on a long run of a's that doesn't end the way it expects, make the engine try an enormous number of ways to match. This is called catastrophic backtracking. The tester runs each pattern in a background worker and stops it after 2 seconds so the page stays usable. Rewrite nested repeats such as (a+)+ as a+.

Is my text sent anywhere?

No. The pattern and the text stay in your browser; matching happens on your device and nothing is uploaded or stored.