Regex Tester & Explainer

Test a regular expression against your own text, see every match and capture group highlighted, get each piece of the pattern explained, and check what JavaScript, PCRE and RE2 actually support. Everything runs in your browser.

About this tool

A regular expression is a tiny language for describing text patterns, and almost every tool that touches text speaks it — search boxes, log filters, code editors, database queries. It is also famously easy to write something that looks right and matches the wrong thing. The fix is not to think harder; it is to watch it run against text you already understand.

This page does that in one place. Type a pattern, pick your flags, paste some text, and every match is highlighted in place while every capture group is listed underneath with its position. Below that, the pattern is split into its individual pieces and each one is explained in plain words — so you can see what \b, (?<=…) and a lazy quantifier actually do, without consulting a cheat sheet.

The third section covers something most testers ignore: the same pattern does not behave identically in every engine. A regex that works perfectly in a browser may be rejected by RE2 on a server, or silently behave differently. The comparison table lists the features where the engines genuinely diverge, so a regex that works locally is less likely to surprise you in production.

Everything is computed on your own device. There is no upload step and no server doing the matching, which matters when the text you are testing is a customer record or a line from a production log.

Why two capture groups with the same value keep their own names

Named groups are matched back to their capture slots by position, not by value. When two groups can hold identical text, such as a repeated year, each name still lands on its own group and neither is dropped.

The obvious implementation is to walk the names and, for each one, find the first capture group holding the same text. It works until two groups legitimately contain the same string — repeated years, repeated words, the same delimiter on both sides — and then the second name is attached to a group that is already named, so the interface shows the first name twice.

The engine reports the offset range of every named group, so the pairing can be done on position instead. A group and a name belong together only if they start and end at the same offsets, and positions are unique in a way that values are not.

The same care shows up in how groups are recorded. A group that took no part in the match is listed as present but empty rather than being dropped, because the numbering of every group after it depends on it keeping its slot.

What happens when a pattern can match nothing at all

The tester still terminates. Patterns that can match an empty string, such as a star quantifier or a lookahead on its own, are advanced one character at a time instead of looping at the same position, so the result list stays finite.

A pattern that matches zero characters is legal and useful: an optional group at the start of a line, a lookahead used as a condition, something you are still building. The trap is that a hand-written loop keeps re-running the same expression at the same index and never gets anywhere, because nothing was consumed to move past it.

The matcher here uses the engine iterator that already knows this rule and steps forward by one code point after an empty match, so a pattern with an empty alternative returns one result per position in the text and then stops. The text length limit and the match cap keep that list bounded.

The cap matters on its own: a global pattern run over a large log can produce thousands of matches, so the list stops at a fixed maximum and says it was truncated rather than growing without limit.

Why the tester runs flags you never selected

Internally the pattern always receives the global flag, so every match can be enumerated, and the result is cut back to the first match afterwards if you left global off. Match indices are requested too, when the engine supports them.

The global flag changes the shape of the answer, not the pattern: it is what lets the matcher iterate at all. If you did not ask for it, the enumeration still runs and only the first match is returned. Deciding which match is first after the fact is more reliable than constraining the engine up front, where other flags behave differently between engines.

The indices flag is added when it is supported and silently dropped when it is not. It is what makes highlighted ranges and capture group positions possible, and it is never shown to you or sent anywhere; it is an implementation detail of the reporting, not part of the pattern you wrote.

Because the flag list is normalised and ordered, the same pattern with the same flags always compiles to the same expression. Duplicate flags are removed rather than passed through, so a string like yyg is accepted and reported as the two flags it actually contains.

Catastrophic backtracking: once a regex runs, it cannot be interrupted

Nested quantifiers like (a+)+$ send the engine into effectively endless backtracking on a long run of a, and JavaScript offers no way to interrupt RegExp.exec. So this tester runs matching inside a worker and lets the host terminate the thread on timeout, because killing the thread is the only hard interrupt available.

Catastrophic backtracking is not an infinite loop but an exponential number of branch attempts. Nested quantifiers give the same stretch of characters many equivalent ways to split, and each failure retries with a different split, so every extra character roughly doubles the time. Twenty or thirty characters is enough to lock up a page.

Worse, it cannot be interrupted on a timer. JavaScript has no regex API that stops after so many seconds, and setTimeout cannot preempt a running exec because that single thread is fully occupied. The only hard stop is to run it on a worker thread and terminate that thread from outside.

The structure here follows from that: the matching logic is a pure function running in a worker, and the timeout policy lives in the host. The split is practical — a timeout is a scheduling concern, not an algorithmic one, and folding it into the model would drag self and setTimeout into code that should be testable on its own.

Three hard limits go with it: patterns up to 1,000 characters, test text up to 200k characters, and at most 500 matches listed. The first two guard against a paste accident freezing the page; the third because beyond 500 rows it is only noise.

Frequently asked questions

Why did my pattern not finish?

Some patterns can backtrack explosively. (a+)+$ against a long run of the letter a is the classic example: each extra character roughly doubles the work, so forty characters is already a trillion steps. This tester runs your pattern in a separate worker and stops it after a short timeout, so the page stays usable. If you see that message, the pattern itself is the problem — usually nested quantifiers, or two quantifiers in a row that can match the same text.

What is the difference between greedy and lazy?

A quantifier is greedy by default: it takes as much as it can and then gives characters back until the rest of the pattern fits. Adding ? makes it lazy, so it takes as little as possible and grows only when it has to. Against <b>bold</b>, <.+> matches the whole string, while <.+?> matches just <b>. Both are correct — they answer different questions.

Does \w match accented letters or Chinese characters?

In JavaScript, no — unless you set the u flag, \w means exactly the ASCII letters, digits and underscore. Chinese, Cyrillic, accented Latin and emoji are all outside it. If you need to treat any letter in any script as a word character, use \p{L} with the u flag, or list the ranges you actually want.

What do the lookahead and lookbehind groups do?

They let you require something without consuming it. \d+(?= dollars) matches the number in "250 dollars" but not the word dollars — the match is just 250. Lookbehind does the same backwards: (?<=\$)\d+ takes the number after a dollar sign without including the sign. They are the standard way to say "only if surrounded by this", and they are exactly what RE2 cannot do.

Why does my pattern give only one result?

Because the g flag is off. Without g, a regular expression stops at the first match — that is the default in JavaScript and in most languages. Turn on g and it will keep going. If you came here from a search box that returned everything, that box was setting g for you.

Is the text I paste sent to a server?

No. The matching happens in your browser, in a worker thread on your own machine. Nothing you type is transmitted or logged anywhere. That is deliberate: production log lines and customer data are the most common things people test regexes against, and neither belongs on someone else’s server.

What does the sticky flag y do?

It anchors each match to the exact position where the previous one ended, instead of searching forward from there. It is how you walk through a string token by token and get told when the pattern stops fitting. PCRE has the same idea under a different name, \G, which is why the comparison table lists them together.

Related tools