Regular Expression Tester: Test JavaScript Regex Patterns

This page runs JavaScript RegExp in your browser — the same engine as Chrome, Firefox, Safari, or Node on this machine — not PCRE. Pattern, flags, test text, and replacement never leave the page. Matches are drawn with text nodes and spans. Nested quantifiers on long strings can still freeze the tab; inputs are capped.

Enter the body only, without wrapping slashes.

Passed to new RegExp(pattern, flags) as a string. Type \d as you would inside /…/. Do not wrap with slashes; flags are the checkboxes. Max 4,096 characters.

Max 256 KiB. Empty input is valid: an empty pattern matches a zero-width match at index 0.

String replacement only (no function). JavaScript tokens: $&, $`, $', $1…, $$, and $<name> when named groups exist. Without g, only the first match is replaced. Max 8,192 characters.

Flags (as supported by this browser)

Applies when g or y is set. Sticky does not scan forward: if the pattern does not match exactly at this index, exec returns null and lastIndex resets to 0. Indexes are UTF-16 code units.

Enter a pattern and test string, then press Test. Results stay in this browser.

Sticky matching and lastIndex

lastIndex is a writable property on the RegExp object. It is consulted only when the pattern is global (g) or sticky (y).

neither g nor y
exec always searches from index 0 and returns at most one match. lastIndex is not used.
g only
Search starts at lastIndex and may skip ahead. After a match, lastIndex becomes the end of that match. After a failure, lastIndex is set to 0.
y only
The match must begin exactly at lastIndex. No forward scan. Failure returns null and sets lastIndex to 0. Useful for tokenizers.
g and y
For exec, sticky wins: still no forward scan, but lastIndex advances so you can loop across adjacent tokens.

JavaScript regex is not PCRE

A pattern that works on regex101’s default PCRE2 flavor, PHP preg_*, or Perl can fail or mean something else here. This tester uses only the ECMAScript engine in this tab.

  • No atomic groups (?>…), possessive quantifiers *+ ++ ?+, recursion (?R), conditionals (?(1)…), or \K.
  • No PCRE-only anchors \A, \Z, \z, or \G. Use ^/$ (and m) or sticky lastIndex instead of \G.
  • Named groups are (?<name>…) and \k<name>, not Python (?P<name>…). Replacement uses $<name>, not ${name}.
  • Modern JavaScript allows variable-length lookbehind. PCRE lookbehind is fixed-length by default. Older browsers may reject lookbehind entirely.
  • There is no x (extended / insignificant whitespace) flag. The JS-only flags here are y (sticky) and, in supporting engines, d/v (not offered as checkboxes).
  • Without u (or v), \w and \d are ASCII-oriented, and \p{L} is not a Unicode property: Annex B treats \p as a literal p, so the pattern can compile and still mean the wrong thing.