Skip to main content
Yoryantra
← Back to Tools

Regex Match Tester

Run JavaScript regex patterns with selected flags, capture groups, match indexes, and replacement semantics.

/g

Enter the JavaScript pattern body without surrounding slashes. An empty pattern is valid JavaScript and can produce zero-length matches.

Matching behavior

Match indexes below are JavaScript string indexes, measured in UTF-16 code units.

Some regular expressions can take extremely long on carefully chosen input. JavaScript regex execution is synchronous here, so a pathological pattern can still make the page unresponsive until the browser finishes it. Test untrusted or complex patterns on small representative samples first.
Pattern, text, matches, and replacement previews stay in the browser. Running a regex does not send the sample text to a server.

What JavaScript actually matches

A regular expression is interpreted by the browser's JavaScript engine. Flags are part of that behavior: g changes a single search into repeated matching, y requires the next match at the current position, and u changes how Unicode code points are consumed by several pattern constructs.

Match positions are still JavaScript string indexes. Those indexes count UTF-16 code units, so a visible character outside the Basic Multilingual Plane can occupy two index positions even under Unicode-aware matching.

Global matching and replacement are separate decisions

Without g, the tester reports the first match only and String.replace() replaces the first match only. With g, both operations continue through later matches. The page does not force global behavior behind the scenes, because doing so would test a different regular expression from the one you selected.

Unmatched is different from empty

An optional capture can be unmatched, which JavaScript reports as undefined. A capture can also participate and match an empty string. Match Details preserves that distinction instead of displaying both cases as the same blank value.

Zero-length matches need care

Patterns such as anchors can match without consuming text. The iterator advances manually after a zero-length global match so it cannot loop forever at one index; Unicode mode advances by a full code point when needed.

Performance is part of regex correctness

Backtracking regex engines can spend a long time exploring failed alternatives. Nested ambiguous quantifiers and attacker-controlled input are especially risky. The page caps text and displayed match counts, but it cannot safely interrupt a synchronous regex that is already consuming CPU in the browser.

JavaScript references

MDN's RegExp.exec() documentation covers stateful global and sticky matching and the zero-length-loop pitfall. String.replace() defines replacement tokens such as $1, $<name>, and the rule that repeated replacement requires a global regex.