Formatters & Code

Regex Tester

Test a JavaScript regular expression and see each match.

Flags g, i, m, s, u, and y, or any flag this browser accepts. Samples over 20,000 characters are refused.

Results appear here.

What the result means

The tester compiles your pattern and flags with the browser RegExp constructor. An illegal pattern or an illegal flag produces a SyntaxError, and that message is shown before any search. When the flags include g, matches are collected with matchAll so each one keeps its index. Without g, only the first match is collected. Matches are listed and marked in the sample. A match that consumes no characters would otherwise leave the search stuck, so the index is advanced past that point. Samples longer than 20,000 characters are rejected first. That length cap is the only guard. A pattern with catastrophic backtracking can still take a long time on a shorter sample, because there is no separate timeout.

Related tools

Advertisement

Questions

Which flags are supported?

The usual flags are g, i, m, s, u, and y, whatever this browser accepts in its regular expression constructor. An unknown flag or a repeated flag throws a syntax error, and that message is shown unchanged. The g flag switches the search so each hit can carry an index. Without g, only the first match is returned.

Why did it hang?

A catastrophic pattern can still be slow. The length cap is the guard, not a full timeout. Nested repeats can force the engine through a huge number of paths even when the sample is under 20,000 characters, and the page cannot interrupt that work. Shorten the sample and avoid stacking open-ended quantifiers.

What is a zero-length match?

Some patterns match a position without consuming characters, such as a lookahead or an empty expression. The page records the index and moves the search forward so it cannot sit on that spot forever. The highlight marks the position even though no text sits inside the match. An empty list means nothing matched, which is a different outcome.