Regex Tools

Regex Tester & Debugger

Write a regular expression, choose flags, and watch matches highlight in real time with their indexes and capture groups. Everything runs in your browser: nothing is uploaded.

Supported flags: g, i, m, s, u, y, d.

Results

Enter a pattern to start testing. Matches will highlight here live.

How it works

The tester builds a regular expression from the pattern and flags you type, using the same new RegExp(pattern, flags) constructor that your own code would call. It then runs that object against the text in the test area. Without the g flag the engine evaluates the first match, and the page reports its index and its capture groups. With g enabled the page walks every match through String.prototype.matchAll, which returns an iterator of match results, so each result carries its own position, its numbered groups, and any named groups defined in the pattern. The matched spans are then spliced back into the text stream to produce the highlights you see.

Nothing is sent to a server. Matching runs inside the page, in your browser's own JavaScript engine.

JavaScript regular expressions are interpreted by a backtracking engine. When a quantified group such as (a+)+ fails to match, the engine revisits every earlier choice point and tries each alternative split in turn. Nested quantifiers multiply the number of revisits, which is why a short input can take a long time to process when a pattern like (a+)+$ runs against a long run of the letter a. The MDN guide to regular expressions calls this catastrophic backtracking and recommends keeping every quantifier on a single token, the way a+ does. Greedy quantifiers consume as much as they can before giving characters back, while lazy ones such as a+? stop as soon as possible. Both return the same match, but they explore different routes, so the choice can affect how much work the engine does.

Aim for patterns that match in a single pass, and test them here before shipping.

Use cases

Validating user input is the most common job. An email address, a URL, a phone number, or an identifier can be checked against a pattern before a form is accepted or a request is sent. A capture group turns that one verdict into several, so the same match can return the local part and the domain of an address at once. The match index and the group breakdown are especially useful when you parse log lines or extract fields from structured text, because they show exactly which characters each part of the pattern consumed, down to the position where each slice began.

Debugging a pattern here is often faster than rewriting it blind.

When a pattern matches too much or too little, change a flag and watch the result update instantly. The index of each match makes the boundary visible, so you can see whether the pattern stopped too early or reached too far. Note that the JavaScript RegExp syntax follows the ECMAScript specification, so extensions from other dialects, such as Perl-compatible regular expressions, may not be valid here. If the pattern is destined for another language, consult that language's own regular expression documentation before relying on a feature this page rejects.

Troubleshooting

  • “Invalid regular expression”: unescaped special characters or an unsupported flag combination. Check the flagged hint next to the pattern field for the character the constructor rejected.
  • Page freezes: nested quantifiers such as (a+)+ trigger catastrophic backtracking, where the engine retries a huge number of splits. Rewrite the pattern with a single quantifier per token.
  • No highlights: add the g flag. Without it only the first match is shown.
  • Unexpected empty matches: zero-width patterns like a* match empty spans, which the tester marks with a thin bar.
  • Unicode surprises: astral-plane characters such as emoji are composed of two code units. The u flag makes the engine treat them as single characters.
  • Backslash confusion: inside a JavaScript string the pattern \d must be written as "\d". The tester accepts the raw form you type, so when you copy a pattern into code, double the backslashes.
  • Group references: a backreference such as  refers to the first capture group, while (?<name>...) defines a named group that you later reference as \k<name>. The results panel lists both forms.

FAQ

Which flags are supported?

The tester supports the standard JavaScript flags: g (global), i (case-insensitive), m (multiline), s (dotAll), u (Unicode), y (sticky), and d (hasIndices).

Why does my regex freeze the page?

Patterns with nested quantifiers, such as (a+)+, can trigger catastrophic backtracking, where the engine retries exponentially many splits. Rewrite the pattern to avoid nested repetition.

What is the difference between using the g flag and leaving it off?

Without g the tester shows only the first match. With g it iterates every match using matchAll(), listing each one with its index, capture groups, and named groups.

Why do I see empty matches?

Zero-width patterns like a* can match empty spans. The tester marks these with a bar so they are not silently ignored.

Is my text uploaded anywhere?

No. Matching runs entirely in your browser. Your pattern and test string never leave the page.

Do lookahead and lookbehind work here?

Yes. JavaScript supports lookahead ((?=...)), negative lookahead ((?!...)) and, since ECMAScript 2018, lookbehind ((?<=...)) and negative lookbehind ((?<!...)). All four are part of the standard syntax the tester accepts.

Is this regex the same as Perl or PCRE?

No. The tester follows the ECMAScript specification that browsers implement. Constructs exclusive to other flavors, such as possessive quantifiers or the \K escape, are not part of JavaScript RegExp syntax and will be rejected here.

The ECMAScript regex references behind this tester

This page follows the ECMAScript regular expression syntax and describes browser behavior only where the sources below define it.

  • MDN: Regular expressions guide. The explanation of flags, character classes, and the backtracking warning in MDN's regular expressions guide is the basis for the How it works section above, including the warning that nested quantifiers can make matching take a very long time.
  • MDN: RegExp reference. The description of RegExp construction, the meaning of the g and u flags, and the named-group syntax in the Troubleshooting and FAQ sections follows the MDN RegExp reference.
  • ECMAScript Language Specification. The precise grammar for patterns and flags, the behavior of matchAll, and the matching algorithm are all defined in the ECMAScript specification, which is the authority for everything this tester accepts or rejects, including the lookbehind syntax added in the 2018 edition.