Regex Tester & Debugger — Match, Groups & Replace

Test a JavaScript regular expression live — every match highlighted, capture groups listed, and a replacement preview, with the browser’s own engine doing the work.

/ /

—

What this tool does

A regular expression is easy to get almost right and hard to debug by eye. This page runs your pattern against your text with the browser’s own JavaScript engine, highlights every match, lists each match and its capture groups, and shows what a replacement would produce — so you can iterate on a pattern until it does exactly what you mean before it ever reaches your code.

Reading the results

ColumnMeaning
#Match number, in order of appearance
atCharacter index where the match begins
matchThe text the pattern consumed
$1, $2…Each capture group, in order of the parentheses in the pattern

Common building blocks

\\d matches a digit, \\w a word character, \\s whitespace, and . any character except a newline. Quantifiers — * (zero or more), + (one or more), ? (optional), {n,m} (a range) — apply to the thing before them. Classes [abc] and [^abc] match one character from, or not from, a set. Anchors ^ and $ pin the match to the start and end of the input, or of each line when the m flag is set.

Flags change the result

Forgetting the global g flag is the single most common surprise: without it the engine stops at the first match, so a page of text looks as though it has only one. The i flag makes matching case-insensitive, m and s change how anchors and the dot treat line breaks, and u is required for correct handling of astral characters such as emoji. Toggle them above and watch the match list change.

Frequently asked questions

Which regex flavour does this use?

JavaScript’s own engine, the same one that runs in a browser or in Node. That means no PCRE features such as recursive patterns or conditionals, but it does include lookahead, lookbehind (in current browsers), named groups, Unicode property escapes with the u flag, and the usual flags g, i, m, s, u and y. A pattern that works in Python or PHP may need changes here, and vice versa.

Why does \d not match Arabic or full-width digits?

In JavaScript without the u flag, \d is exactly [0-9] regardless of the script. Other digits are matched by \p{Nd} when the u flag is set — Arabic-Indic ٣, Devanagari ३ and full-width 3 are all decimal digits by Unicode category. If you want “any digit a reader would call a digit”, use \p{Nd}; if you want ASCII only, keep \d.

What do the flags change?

g finds all matches instead of stopping at the first; i ignores case; m makes ^ and $ match at line boundaries rather than only at the start and end of the subject; s makes . match newlines; u enables Unicode mode (property escapes, code-point semantics); y anchors the next match at lastIndex. Combining g and y is rarely useful; forgetting g is the usual reason only one match is highlighted.

Which regular-expression flavour is this?

JavaScript’s, exactly — the engine wraps the browser’s own RegExp object, so a pattern behaves here precisely as it would in your code. That matters because regex has subtly different dialects; testing a PHP or PCRE pattern here can give different results for the same-looking expression.

How do the flags work?

g finds every match instead of only the first. i ignores case. m makes ^ and $ match at each line break. s lets the dot match newlines too. u treats the pattern as Unicode code points, which is what you want for emoji and non-BMP characters. y (sticky) matches only from the last position. Toggle them under the pattern.

Why did my pattern return no matches?

The usual reasons are an unescaped special character (a literal dot needs \.), a missing global flag so only the first match is returned, or an anchor that does not fit the input. The panel reports compile errors with the engine’s own message, and shows the match count so you can tell "no match" from "could not compile".

What are capture groups?

Parentheses in a pattern create groups, and each group’s matched text is listed under the match. Named groups — (?<year>\d{4}) — are shown by name, and can be used in the replacement as $<name>. Numbered groups are $1, $2 and so on.

Can a pattern hang the page?

In principle a badly written pattern with nested quantifiers can backtrack for a very long time. This tool caps the scan by both match count and a time budget, so a pathological pattern stops early and says so rather than freezing the tab.

Is my text uploaded?

No. Matching runs in your browser against the pattern you type; neither the pattern nor the subject is sent anywhere.

Sources

  • ECMAScript Language Specification — RegExp (Patterns, Flags and the RegExp object).

Everything runs in your browser — nothing you type is uploaded.