📖 Regex Cheat Sheet
A searchable quick-reference for common regular expression syntax (JavaScript flavor). To actually test a pattern against sample text, use the Regex Tester.
What the filter searches
The sheet holds 33 entries covering character classes, anchors, quantifiers, groups, lookaround, backreferences and the five flags. Your text is matched as a plain substring - not as a regex - against all three columns joined together, so it finds the token, the description or the example:
"group" -> 4 rows: (...) (?:...) (?<name>...) \1
"flag" -> 7 rows: the five flags, plus ^ and $, whose
descriptions mention the m flag
Everything shown is the JavaScript flavour. To run a pattern against sample text rather than look up syntax, use the Regex Tester.
Traps the table does not spell out
- Quantifiers here are all greedy. Append a
?for the lazy form:<.+>swallows a whole line of HTML,<.+?>stops at the first>. - Escaping differs by context. In a
/.../literal\dis one backslash; insidenew RegExp("\d")it needs two, because the string eats one. - Lookbehind is newer than the rest. Node and Chrome have had it for years, Safari only since 16.4, and Python or Java reject variable-length lookbehind outright.
replace changes only the
first hit and match returns capture groups rather than a list of
every match. Most "why did only one get replaced" bugs are this.Frequently asked questions
What does \b mean in a regular expression?
A word boundary: the zero-width position between a word character and anything else. It matches no text itself, which is why /\bcat\b/ finds cat in "a cat sat" but not inside "category".
Is \d the same as [0-9]?
In JavaScript, yes for ASCII, and \d stays ASCII-only even with the u flag. In .NET and Python 3 the shorthand also matches other Unicode digits such as Arabic-Indic numerals, so [0-9] is the safer choice when you mean exactly the ten ASCII digits.
How do I match a literal dot or question mark?
Escape it with a backslash - \. and \? - or put it inside a character class, where most metacharacters lose their meaning: [.?] matches either one.