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.
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.
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.
Highlighted matches
Amber and green underlines alternate so adjacent matches stay distinct without relying on color alone. A thin accent bar marks a zero-width match. HTML in the test string is shown as text.
Match list
Index and end are 0-based UTF-16 offsets; the end index is exclusive. Unmatched optional groups show as unmatched, not as an empty string. Named groups come from match.groups.
| # | Index | End | Length | Match | Capture groups |
|---|
Replace preview
Preview from String.prototype.replace with this pattern, flags, starting lastIndex, and replacement string.
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
execalways 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^/$(andm) 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 arey(sticky) and, in supporting engines,d/v(not offered as checkboxes). - Without
u(orv),\wand\dare ASCII-oriented, and\p{L}is not a Unicode property: Annex B treats\pas a literalp, so the pattern can compile and still mean the wrong thing.