/regex rosetta stone/i

JavaScript

V8 (Node.js)
About
ECMAScript RegExp, backtracking. The base column is a pattern without the u or v flag; both flags change how the pattern is read.
Verified on
Node.js 24.22.3
Offsets are counted in UTF-16 code units.
Found in
Node.js, Chrome, Deno
its own documentation
Flags
i ignore casem multilines dotallu unicodev unicode sets
Modes
This page describes no u or v flag. u flag v flag rows show where another mode reads a pattern differently.
Character classes 9 of 26
SyntaxMatchesNotesTry
. Any characterAny single character. Whether that includes a newline depends on the dialect and its flags.

Does not match a newline.

test
[abc]not[^abc] One of a set of characters test
[a-z] One of a range of characters test
[\]] Backslash escape inside a setInside a bracket expression a backslash takes the special meaning from the next character. Where this is missing, a backslash there is a member like any other. test
[\d] Class escape inside a setA class escape such as the one for a digit, used as a member of a bracket expression. test
[\D] Negated class escape inside a setA negated class escape, such as the one for anything but a digit, used as a member of a bracket expression. test
\dnot\D Digit

ASCII digits only: 0 to 9.

test
\wnot\W
v flag\w[[:alnum:]_]not\W
Word characterA letter, a digit or an underscore.

ASCII only: A to Z, a to z, 0 to 9 and _.

test
\snot\S Whitespace

Also matches the no-break space.

test
n/a Horizontal whitespaceA space or a tab, but not a line break. not in JavaScript

Tried: \h compiles, and matches as plain text or not at all.

who has it
n/a Vertical whitespaceA line break character of any kind. not in JavaScript

Tried: \v compiles, and matches as plain text or not at all.

who has it
n/a Any character except newlineNever matches a newline, whatever the flags. not in JavaScript

Tried: \N compiles, and matches as plain text or not at all.

who has it
n/a Any line break sequenceOne line break, with CR LF taken as a single unit. not in JavaScript

Tried: \R compiles, and matches as plain text or not at all.

who has it
n/a Alphabetic character (shorthand) not in JavaScript

Tried: \a compiles, and matches as plain text or not at all.

who has it
n/a Lowercase letter (shorthand) not in JavaScript

Tried: \l compiles, and matches as plain text or not at all.

who has it
n/a Uppercase letter (shorthand) not in JavaScript

Tried: \u compiles, and matches as plain text or not at all.

who has it
n/a Hexadecimal digit (shorthand) not in JavaScript

Tried: \h compiles, and matches as plain text or not at all.

who has it
n/a Class intersectionCharacters that are in both classes. not in JavaScript

Tried: [a-z&&[^a-m]] compiles, and matches as plain text or not at all.

who has it
n/a
v flag[X--Y]
Class subtractionCharacters in the first class that are not in the second. not in JavaScript

Tried: [a-z&&[^aeiou]] compiles, and matches as plain text or not at all.

who has it
n/a Head-of-word character (shorthand)A letter or the underscore: what a word may start with. not in JavaScript

Tried: \h compiles, and matches as plain text or not at all.

who has it
n/a Octal digit (shorthand) not in JavaScript

Tried: \o compiles, and matches as plain text or not at all.

who has it
n/a Identifier characterA character allowed in an identifier. In Vim the set comes from the 'isident' option. not in JavaScript

Tried: \i compiles, and matches as plain text or not at all.

who has it
n/a Keyword characterA character allowed in a keyword. In Vim the set comes from the 'iskeyword' option. not in JavaScript

Tried: \k compiles, and matches as plain text or not at all.

who has it
n/a File name characterA character allowed in a file name. In Vim the set comes from the 'isfname' option. not in JavaScript

Tried: \f compiles, and matches as plain text or not at all.

who has it
n/a Printable characterA character that is displayed as itself. In Vim the set comes from the 'isprint' option. not in JavaScript

Tried: \p compiles, and matches as plain text or not at all.

who has it
n/a Any single byteOne code unit, even where that is part of a longer character, and even a newline. not in JavaScript

Tried: \C compiles, and matches as plain text or not at all.

who has it
Anchors 4 of 14
SyntaxMatchesNotesTry
^ Start of the text or lineStart of the text. With a multiline flag, or always in some dialects, also the start of each line. test
$ End of the text or line

Matches only at the very end, not before a final newline.

test
n/a Start of the textStart of the text only, whatever the flags. not in JavaScript

Tried: \Aa compiles, and matches as plain text or not at all.

who has it
n/a End of the textThe very end of the text, whatever the flags. not in JavaScript

Tried: a\z compiles, and matches as plain text or not at all.

who has it
n/a End of the text, or before a final newline not in JavaScript

Tried: a\Z compiles, and matches as plain text or not at all.

who has it
\b Word boundaryThe position between a word character and a non-word character or an end of the text.

ASCII word characters only: a letter outside ASCII counts as a non-word character.

test
\B Not a word boundary test
n/a Start of a word not in JavaScript

Tried: \<foo compiles, and matches as plain text or not at all.

who has it
n/a End of a word not in JavaScript

Tried: foo\> compiles, and matches as plain text or not at all.

who has it
n/a Where the previous match endedThe position where the last match stopped, or the start of the text for the first match. not in JavaScript

Tried: \Ga compiles, and matches as plain text or not at all.

who has it
n/a Reset the start of the matchEverything matched so far is required but left out of the reported match. not in JavaScript

Tried: foo\Kbar compiles, and matches as plain text or not at all.

who has it
n/a Start of symbolBefore a run of word and symbol characters, such as an identifier with an underscore in it. not in JavaScript

Tried: \_<b compiles, and matches as plain text or not at all.

who has it
n/a End of symbol not in JavaScript

Tried: a\_> compiles, and matches as plain text or not at all.

who has it
n/a Cursor positionWhere the editor's cursor is in the buffer being searched. not in JavaScript

The y flag makes a match start exactly at lastIndex, a position kept on the RegExp object, not an editor cursor.

doc Not run on an engine: taken from the documentation.

who has it
Quantifiers 8 of 9
SyntaxMatchesNotesTry
X? Zero or one test
X* Zero or more test
X+ One or more test
X{N} Exactly N times test
X{N,} N or more times test
X{0,M} At most M times test
X{N,M} Between N and M times test
X*?X+?X?? Lazy quantifierRepeat as few times as possible instead of as many as possible. test
n/a Possessive quantifierRepeat as many times as possible and never give any of it back. not in JavaScript

Tried: a*+b does not compile.

who has it
Groups and alternation 6 of 16
SyntaxMatchesNotesTry
(X) Capture group test
(?:X) Non-capturing group test
(?<NAME>X) Named capture group test
X|Y Alternation

Takes the first alternative that matches, even when a later one is longer.

test
\N Backreference by numberThe same text that capture group N matched. test
\k<NAME> Backreference by name test
n/a Backreference by relative positionThe group N groups back from here. not in JavaScript

Tried: (a)\g-1 compiles, and matches as plain text or not at all.

who has it
n/a Atomic groupOnce the group has matched, the engine never tries a different way to match it. not in JavaScript

Tried: (?>a+)b does not compile.

who has it
n/a Branch reset groupEvery alternative numbers its capture groups from the same start. not in JavaScript

Tried: (?|(a)|(b)) does not compile.

who has it
n/a ConditionalMatch one pattern if a capture group took part, otherwise another. not in JavaScript

Tried: (<)?a(?(1)>|!) does not compile.

who has it
n/a Recurse into the whole pattern not in JavaScript

Tried: \((?:a|(?R))\) does not compile.

who has it
n/a Call a group as a subroutineMatch the pattern of capture group N again at this point, not the text it matched. not in JavaScript

Tried: (a|b)(?1) does not compile.

who has it
n/a Comment not in JavaScript

Tried: a(?#note)b does not compile.

who has it
n/a Explicitly numbered groupA capture group that is given its number, whatever its position. not in JavaScript

Tried: (?<2>a) does not compile.

who has it
n/a Call an earlier group by relative positionMatch the pattern of the Nth group before this point again. not in JavaScript

Tried: (a|b)(?-1) does not compile.

who has it
n/a Call a later group by relative positionMatch the pattern of the Nth group after this point here as well. not in JavaScript

Tried: (?+1)(a|b) does not compile.

who has it
Lookaround 4 of 4
SyntaxMatchesNotesTry
(?=X) LookaheadWhat follows must match X, but is not part of the match. test
(?!X) Negative lookahead test
(?<=X) LookbehindWhat comes before must match X, but is not part of the match.

The lookbehind may have unbounded length.

test
(?<!X) Negative lookbehind test
Escape sequences 12 of 16
SyntaxMatchesNotesTry
\. Escape a special characterTake the next character literally. test
n/a Quote a run of textTake everything between the markers literally. not in JavaScript

Tried: \Qa.b\E compiles, and matches as plain text or not at all.

who has it
\t Tab test
\n Newline test
\r Carriage return test
\f Form feed test
\v Vertical tab test
n/a Alert (bell) not in JavaScript

Tried: \a compiles, and means something else.

who has it
[\b] Backspace test
n/a Escape character not in JavaScript

Tried: \e compiles, and means something else.

who has it
\cC Control characterThe control character typed as Ctrl plus the letter. test
\OOO
u flagn/a
v flagn/a
Character by octal code test
\xHH Character by two-digit hex code test
\uHHHH
u flag\uHHHH\u{HHHH}
v flag\uHHHH\u{HHHH}
Character by Unicode code point test
n/a Character by Unicode name not in JavaScript

Tried: \N{DIGIT ONE} compiles, and matches as plain text or not at all.

who has it
\0\x00\u0000\u{0} NUL characterThe character with code 0.

\0 cannot be followed by a decimal digit, and \u{0} needs the u or v flag. Neither source states a restriction on NUL in a pattern or a subject.

doc Not run on an engine: taken from the documentation.

Flags and modes 4 of 14
SyntaxMatchesNotesTry
flag i Ignore case test
flag m MultilineThe line anchors also match at the start and end of every line. test
flag s Dot matches newline test
n/a Free spacingWhitespace in the pattern is ignored, and a # starts a comment. not in JavaScript

Tried: (?x)a b does not compile.

who has it
n/a Swap greedy and lazy not in JavaScript

Tried: (?U)a.*c does not compile.

who has it
n/a Turn a mode on inside the patternApplies from this point to the end of the pattern or the enclosing group. not in JavaScript

Tried: (?i)ab does not compile.

who has it
n/a Turn a mode on in the middle of the patternThe mode applies from where the flag stands, not to what comes before it. Some dialects accept an inline flag only at the very start of the pattern. not in JavaScript

Tried: a(?i)b does not compile.

who has it
(?FLAGS:X) Turn a mode on for one group test
n/a Turn a mode off inside the pattern not in JavaScript

Tried: (?i)a(?-i)b does not compile.

who has it
n/a ASCII-only classesMakes the shorthand classes such as the digit class match ASCII characters only. not in JavaScript

Tried: (?a)\d does not compile.

who has it
n/a Unicode classesMakes the shorthand classes such as the digit class match by Unicode property. not in JavaScript

Tried: (?u)\d does not compile.

who has it
n/a No automatic capturePlain parentheses group without capturing; only named groups capture. not in JavaScript

Tried: (?n)(a)(?<x>b) does not compile.

who has it
n/a Locale-dependent classesClasses and case folding follow the current locale. not in JavaScript

doc Not run on an engine: taken from the documentation.

who has it
n/a Native character set rulesPerl's rules from before 5.14: the pattern and the text decide between native and Unicode rules. not in JavaScript

A d flag exists but means "generate indices for substring matches", unrelated to the Perl mode.

doc Not run on an engine: taken from the documentation.

who has it
POSIX named classes 0 of 1
SyntaxMatchesNotesTry
n/a POSIX named classA named set of characters, written inside a bracket expression. not in JavaScript

Tried: [[:alnum:]]+ compiles, and matches as plain text or not at all.

who has it
POSIX collating symbols 0 of 2
SyntaxMatchesNotesTry
n/a Equivalence classEvery character that collates the same as X in the current locale. not in JavaScript

Tried: [[=a=]] compiles, and matches as plain text or not at all.

who has it
n/a Collating symbol by nameA single collating element, written by its POSIX name inside a bracket expression. not in JavaScript

Tried: [[.SOH.]] compiles, and matches as plain text or not at all.

who has it
Unicode properties 0 of 4
SyntaxMatchesNotesTry
n/a
u flag\p{NAME}not\P{NAME}
v flag\p{NAME}not\P{NAME}
Unicode general category not in JavaScript

Tried: \p{L} compiles, and matches as plain text or not at all.

who has it
n/a
u flag\p{Script=NAME}not\P{Script=NAME}
v flag\p{Script=NAME}not\P{Script=NAME}
Unicode script not in JavaScript

Tried: \p{Latin} compiles, and matches as plain text or not at all.

who has it
n/a Extended grapheme clusterOne character as a reader sees it: a base character with its combining marks. not in JavaScript

Tried: \X compiles, and matches as plain text or not at all.

who has it
n/a Unicode text boundaryA boundary as Unicode's segmentation rules define it, which is not the same as a boundary between word and non-word characters. not in JavaScript

Tried: e\b{gcb} compiles, and matches as plain text or not at all.

who has it
Syntax table classes 0 of 2
SyntaxMatchesNotesTry
n/a Syntax classA character with the given role in the syntax table: whitespace, word, symbol, punctuation, a bracket. not in JavaScript

Tried: \s- compiles, and matches as plain text or not at all.

who has it
n/a Character categoryA character in one of the editor's character categories, most of which are scripts. not in JavaScript

Tried: \ca compiles, and matches as plain text or not at all.

who has it
Host language 9 of 15
SyntaxMatchesNotesTry
/PATTERN/new RegExp("PATTERN") Pattern in source codeHow a pattern is written where it is used: a regex literal with its delimiters, or the kind of string the documentation recommends.

In a literal a / outside a character class must be escaped as \/, and an empty pattern is /(?:)/ because // starts a comment. In the string given to RegExp every backslash is doubled.

doc Not run on an engine: taken from the documentation.

/PATTERN/FLAGSnew RegExp("PATTERN", "FLAGS") Flags outside the patternWhere flags such as case-insensitive go when they are not written inside the pattern.

FLAGS is a run of letters from d, g, i, m, s, u, v, y, each at most once.

doc Not run on an engine: taken from the documentation.

const re = /PATTERN/;const re = new RegExp("PATTERN"); Compile once and reuseBuild a pattern object and keep it.

A reused RegExp with the g or y flag carries lastIndex state from one call to the next.

doc Not run on an engine: taken from the documentation.

/PATTERN/.test(TEXT)/PATTERN/.exec(TEXT)TEXT.match(/PATTERN/) Search a textTest whether the pattern matches anywhere in a text, or get the first match.

Not anchored. With the g or y flag test and exec start at lastIndex and update it.

doc Not run on an engine: taken from the documentation.

TEXT.matchAll(/PATTERN/g)TEXT.match(/PATTERN/g) Every matchGet all the matches that do not overlap.

matchAll throws a TypeError without the g flag and yields full match arrays. match with g returns only the matched strings, without groups.

doc Not run on an engine: taken from the documentation.

TEXT.replace(/PATTERN/, REPLACEMENT)TEXT.replace(/PATTERN/g, REPLACEMENT)TEXT.replaceAll(/PATTERN/g, REPLACEMENT) Replace matches

replace changes the first match unless the regex has the g flag. replaceAll requires the g flag.

doc Not run on an engine: taken from the documentation.

m[NUM]m.groups.NAME Captured group, in codeRead what a group captured after a match.

m is the array returned by exec, by match without g, or yielded by matchAll. m[0] is the whole match, and m.groups is undefined when the pattern has no named groups.

doc Not run on an engine: taken from the documentation.

$NUM$<NAME> Captured group, in replacement text

At most two digits are read, and a two-digit number above the group count is taken as one digit plus a literal digit. Write group 1 as $01 to put a digit after it.

doc Not run on an engine: taken from the documentation.

$& Whole match, in replacement text

A literal dollar sign is written $$.

doc Not run on an engine: taken from the documentation.

n/a Match once until resetA match operator that succeeds one time only, until it is reset. not in JavaScript

doc Not run on an engine: taken from the documentation.

who has it
n/a Keep the position after a failed matchIn a repeated search, a failed match does not send the next one back to the start. not in JavaScript

A failed match with the g or y flag always sets lastIndex to 0. lastIndex is writable, so code can save and restore it.

doc Not run on an engine: taken from the documentation.

who has it
n/a Keep the matched text for laterAsk for the matched text, and the text around it, to be saved. not in JavaScript

No flag is needed or offered: a match array always has index and input. The deprecated statics RegExp.lastMatch, RegExp.leftContext and RegExp.rightContext hold the last match and its surroundings.

doc Not run on an engine: taken from the documentation.

who has it
n/a Interpolate and compile only onceA pattern literal with variables in it is built the first time and never again. not in JavaScript

A regex literal has no interpolation and becomes a new RegExp each time it is evaluated. Build a dynamic pattern once with new RegExp and keep the object.

doc Not run on an engine: taken from the documentation.

who has it
n/a Code inside a patternHost-language code that runs when the match reaches it. not in JavaScript

doc Not run on an engine: taken from the documentation.

who has it
n/a Pattern computed during the matchCode inside the pattern whose result is matched as a pattern at that point. not in JavaScript

doc Not run on an engine: taken from the documentation.

who has it

Every row was run on the engine named above, except the rows marked doc: those describe something no regex engine can run by itself, such as the syntax of the host language, and are taken from the documentation they link to. For a row marked "not in JavaScript", the spelling other dialects use was tried and the line starting "Tried" says what it did here; that shows the spelling does not work, not that no other spelling exists.