Skip to main content
Ganesh Joshi
Back to Cheatsheets

Regex cheat sheet (JavaScript)

Updated 2026-02-14

JavaScript regex syntax quick reference: character classes, quantifiers, anchors, groups, flags.

Character classes

. any char (except newline). \d digit, \D non-digit. \w word [a-zA-Z0-9_], \W non-word. \s whitespace, \S non-whitespace. [abc] any of, [^abc] not. [a-z] range.

Quantifiers

* 0 or more, + 1 or more, ? 0 or 1. {n} exactly n, {n,} n or more, {n,m} between. *? +? non-greedy (lazy).

Anchors and groups

^ start, $ end (use m for per-line). \b word boundary, \B non-boundary. (x) capturing, (?:x) non-capturing, (?<name>x) named. x|y alternation. \n backreference.

Lookahead / lookbehind

(?=x) positive lookahead, (?!x) negative lookahead. (?<=x) positive lookbehind, (?<!x) negative lookbehind.

Flags (JavaScript)

g global, i ignore case, m multiline, s dotAll (. matches newline), u unicode, y sticky.

Regex cheat sheet (JavaScript) | Cheatsheet | Ganesh Joshi