JavaScript Regex Tester

Test and debug JavaScript regular expressions live with match highlighting, capture-group inspection, plain-language pattern explanations and a replacement preview. Everything runs privately in your browser.

Ready · 0 matches

Pattern, flags & text

/g
Enter the pattern without surrounding slashes. Pasted literals such as /\w+/gi are detected safely. Use single backslashes here.
Flags
JavaScript replacement tokens are applied exactly as entered.

Results

Evaluating the starter example…
Whole matchCapture groupZero-length match

Replacement preview

Matches & capture groups

Ranges use JavaScript UTF-16 code-unit indices. When astral Unicode characters change the count, code-point positions are also shown.

Advertisement

Live pattern explanation

Select or hover a token to connect it to the expression. Explanations are a debugging aid; the browser remains the authority on valid syntax.

Try a working example

Each preset loads a pattern, flags and realistic test text. Expected results describe this exact sample, not universal validation.

Generated JavaScript code

Regex literals escape forward slashes. Constructor strings also escape backslashes and quotes because the pattern passes through JavaScript string syntax first.

Regex test cases (optional)

Add strings that should match or should not match, then run them together to catch regressions.

Interactive JavaScript regex reference

Regex troubleshooting guide

Only one match appears

Turn on g. Without the global flag, JavaScript stops after the first match.

Anchors reject useful text

^ and $ restrict a match to an entire input, or to each line with m. Remove or narrow anchors when searching within longer text.

The match is too broad

Greedy quantifiers take as much as they can. Prefer a precise character class or a lazy form such as .*?, while still giving it a clear boundary.

A literal character acts like syntax

Escape metacharacters such as ., +, ?, ( and [ with a backslash. Constructor strings need the backslash escaped again.

Lines or dots behave unexpectedly

m changes ^ and $; it does not make dot span lines. Use s for dotAll behavior.

A PCRE or Python pattern is invalid

This page uses ECMAScript. Atomic groups, branch reset groups, inline mode modifiers and some other flavor-specific constructs are not JavaScript syntax.

Named groups are missing

Use (?<name>...) and refer to it with \k<name> in a pattern or $<name> in a replacement.

Emoji indices look longer than expected

Without Unicode mode JavaScript commonly operates on UTF-16 code units, not Unicode code points. Even with u, indices remain code-unit offsets; this inspector shows code-point positions when they differ.

Frequently asked questions

Which regex flavor is used?

This tester uses the native JavaScript RegExp engine in your browser, following ECMAScript syntax rather than PCRE, Python or another regex flavor.

Is my text uploaded?

No. Patterns, test text, replacements and test cases are processed locally in your browser and are never sent to Starlight Tools.

What do the JavaScript regex flags do?

g finds all matches, i ignores letter case, m makes ^ and $ work per line, s lets dot match line breaks, u enables Unicode-aware parsing, y matches only at lastIndex, and d returns match indices.

Why is my regex invalid?

Common causes are an unclosed group or character class, an invalid escape, a repeated quantifier, or syntax from another regex flavor. The error shown comes from your browser's RegExp constructor.

Why do I see only one match?

Enable the global g flag to continue searching after the first match. It is enabled by default in this tester.

How do capture groups work?

Parentheses capture parts of a match as numbered groups. Use (?<name>...) for a named group and (?:...) when grouping without capturing.

Does JavaScript support lookbehind?

Modern JavaScript engines generally support positive (?<=...) and negative (?<!...) lookbehind, but the tester feature-detects support because older browsers may reject it.

How do replacement tokens work?

In replacement text, $& inserts the whole match, $1 and $2 insert numbered groups, and $<name> inserts a named group. Use $$ to insert a literal dollar sign.

Why does a JavaScript pattern differ from PCRE or Python?

Regex flavors have different syntax and features. JavaScript does not support every PCRE or Python construct, and constructor strings require an extra level of backslash escaping that regex literals do not.

Methodology & privacy

Native engine: tests use your browser's JavaScript RegExp implementation inside a disposable Web Worker with an 800 ms limit. Match indices, lookbehind and other newer capabilities are feature-detected.

Private processing: your pattern, text, replacement and test cases never leave this browser. A permalink contains data only in the URL you choose to copy.

Technical review: reviewed by Starlight Robotics engineering on . Syntax claims follow the MDN JavaScript RegExp reference and the ECMAScript specification.

Explore more tools