Regex Tester

Test regular expressions with live highlighting, capture groups and replace preview. Runs in a Web Worker with a time limit, so a runaway pattern cannot freeze the page.

All processing happens in your browser. Nothing is uploaded.

Matches (0)

No matches.

Matching runs in a Web Worker with a time limit. JavaScript cannot interrupt a regex once it starts, so a runaway pattern would otherwise freeze the whole page — which is exactly what happens on most online regex testers.

How to use

  1. Type your pattern in the top field — no surrounding slashes needed.
  2. Toggle the flags you want. g is on by default; without it only the first match is found.
  3. Paste your test text. Matches highlight as you type.
  4. Fill in a replacement to preview the result — $1 for numbered groups, $<name> for named ones.

About regular expressions and the thing that bites

A regular expression describes a pattern rather than a literal string, and the engine that matches it works by trying possibilities and backing up when they fail. That backtracking is what makes regexes expressive, and it is also the source of the one failure mode worth understanding.

Consider (a+)+b against the string aaaaaaaaaaaaaaaaaaaaaaaaaaaa. There is no b, so the match must fail — but before concluding that, the engine tries every way of splitting those as between the inner and outer quantifier. The number of splits doubles with each additional character, so at thirty as the engine is working through hundreds of millions of possibilities. This is catastrophic backtracking, and it has taken down production systems: a regex in a log-parsing rule meeting an unusual line is a well-documented outage pattern.

What makes this dangerous in a browser is that JavaScript cannot interrupt a running regex. There is no timeout parameter, no cancellation, no way for other code to run. A pattern that backtracks on the main thread freezes the tab completely — no scrolling, no clicking, no stopping it. Most online regex testers work this way, which is why an experimental pattern can kill the very page you are using to experiment.

This tool runs the match in a Web Worker with a time limit. The Worker is a separate thread, so the page stays responsive while it works, and if the pattern is still running after the limit the entire Worker is terminated. That termination is the only reliable remedy — nothing can make a backtracking regex stop on its own.

The shape warning shown above the results is a heuristic that looks for nested quantifiers. It is deliberately not a blocker: whether a pattern actually explodes depends on the input, and deciding it in general is undecidable. The warning tells you where to look; the timeout is what actually protects you.

Frequently asked questions

Why does this run the match in a background thread?

Because a JavaScript regex cannot be interrupted once it starts. A pattern like (a+)+b takes exponential time on text that almost matches, and on the main thread that means the tab freezes with no way out but closing it. Running the match in a Web Worker lets the page stay responsive and lets a runaway pattern be killed after a time limit. This is not a theoretical concern in a regex tester specifically: half-finished patterns are exactly the shape that backtracks catastrophically, and you write a lot of half-finished patterns while testing.

Which flavour of regex is this?

JavaScript's, because it runs in your browser using the engine that is already there. Most syntax is shared across languages, but there are real differences: JavaScript has no possessive quantifiers or atomic groups, lookbehind is comparatively recent, and \\d matches only ASCII digits unless you think about Unicode. If your pattern is destined for Python, PCRE or Go, test the tricky parts in that language too.

Why do I get one match when I expected several?

The g flag is off. Without it, matching stops at the first result — that is the language's behaviour, not a limitation here. Turn on g to collect every match.

What is the difference between the m and s flags?

They are often confused because both involve line breaks. m changes what ^ and $ mean: with it they match at the start and end of every line rather than only the whole string. s changes what . means: with it the dot also matches newline characters, which it otherwise never does. They are independent and you may want either, both or neither.

Is my text sent anywhere?

No. Both the pattern and the text stay in your browser. This is worth knowing because regex testing often involves production data — log lines, real email addresses, sample records — pasted in to check a pattern against something realistic.

Why is my pattern flagged as risky when it works fine?

The warning is a shape heuristic: it looks for nested quantifiers such as (a+)+ that are the usual cause of catastrophic backtracking. Whether a given pattern actually blows up depends on the input, so a flagged pattern may run instantly on your test text and still hang on a longer one. Deciding this properly is undecidable in general, which is why the real safeguard is the timeout rather than the warning.