Skip to the tool

Regex tester

MDV Tools

Test a JavaScript regex against your text as you type.

Runs on this device Works offline
0 characters
Matches
type a pattern above
How this works

The pattern and the ticked flags go straight into new RegExp(pattern, flags), so the engine is this browser's own ECMAScript regular expression engine, and a pattern behaves here as it does in JavaScript in this browser — on the text as this page holds it. A textarea stores every line break as a line feed, so text pasted with Windows CRLF line endings arrives without its carriage returns, and \r or \r\n finds nothing here that it would find in the original file. The v box is shown only when this browser's engine accepts v; the engine refuses u and v together, so ticking one clears the other. When the constructor throws, its message is shown as it is; that message carries no position, so the tokeniser described next is asked for one, and when it sees the problem the character is named and marked with a caret. With g on, matches come from String.prototype.matchAll; with it off, from a single exec, which is why only the first match is shown then. lastIndex is set to 0 before that exec and before the replace, so with y on the first match must start at index 0. The highlight is built from text nodes and mark elements, never from markup, so text that looks like HTML stays text. A zero-width match, such as \b, has no text to mark, so it is drawn as ¦ — a marker that is not in your text — and the count says how many there are. The replacement is String.prototype.replace with your string, so $1, $<name>, $&, $`, $' and $$ mean what they mean there, an empty replacement deletes each match, and without g only the first match is replaced. With d on, the table adds each group's start and end from match.indices.

The explanation is a small tokeniser written in this file. It walks the pattern once and names anchors, classes, escapes, groups, lookarounds, backreferences, quantifiers and alternation. It reads token by token, so it does not verify that a backreference points at an existing group, and it does not read v-flag set operations or nested classes. It does name the problems it can see — a class or group never closed, a ) with no group open, a lone backslash at the end, a quantifier with nothing before it that can repeat — and when the engine refuses a pattern, the first of those is the position shown. The engine's message still wins: it can be about a problem the tokeniser does not see, and when the tokeniser sees none, no position is given. Group numbers in the table come from the same walk.

Catastrophic backtracking cannot be detected from outside: a pattern such as (a+)+$ against a long run of a will freeze this tab as it would freeze any program, and that is the engine, not the tool. To keep the usual cases quick, the text is capped at 200,000 characters and the pattern at 5,000; the highlight and the table show the first 5,000 matches and the count says when there are more. The table shows the first 80 characters of a match or group and marks the cut. Nothing is uploaded: there is no server in this file.

The Dark button remembers its setting in this browser's local storage. Nothing you type or drop into the page is stored.