What this tool does
A JavaScript regular expression tester with live match highlighting, capture-group breakdown, and protection against catastrophic backtracking. The flags input accepts the standard set (g i m s u y), and matches are listed with their start and end indices and any named or numbered groups.
When you'd use it
- Drafting a regex against a representative sample before pasting it into code.
- Confirming what a regex from someone else actually matches (and what it doesn't).
- Tightening a pattern that was too greedy or too loose in production.
- Practicing the JavaScript flavor specifically, since each language has subtly different semantics.
How it works
The pattern is compiled with new RegExp(pattern, flags) and then run against the test text. Matching happens inside a Web Worker with a 1-second timeout — if the pattern triggers catastrophic backtracking on the supplied input, the worker is terminated and you see a "regex took too long" error instead of a frozen tab. This is a real concern for patterns like (a+)+b against long inputs of a.
Notes
Why is a Web Worker needed? Browser regex engines don't expose a timeout, and a single slow regex can hang the main thread for tens of seconds. Running matching inside a Worker means we can worker.terminate() and stay responsive.
Does this support Perl/PCRE features? No — only what JavaScript supports. \K, atomic groups, possessive quantifiers, and recursive patterns are not part of the JS regex grammar. Lookbehind and named groups are.
My regex matches in this tool but not in my code. Check the flags. The u flag changes how some character classes match Unicode; the g flag affects state across calls when you reuse the regex object.
Related tools
- Diff Checker — compare before/after when refactoring patterns
- JSON Formatter — for testing patterns against API payloads