Regex Cheatsheet
Perl/JS-compatible regex essentials. Works in most languages with tweaks.
1 credit
Character classes
5 itemsAny char (not newline)
.Word char [A-Za-z0-9_]
\w / \W (not word)Digit
\d / \D (not digit)Whitespace
\s / \S (not whitespace)Custom set
[abc] [^abc] [a-z]Quantifiers
6 items0 or more
*1 or more
+0 or 1
?Exactly n
{n}n to m
{n,m}Lazy (non-greedy)
*? +? ??Anchors & boundaries
2 itemsStart / end of string
^ $Word boundary
\b \BGroups
5 itemsCapture
(abc)Non-capture
(?:abc)Named
(?<name>abc)Backref
\1 or \k<name>Lookahead / behind
(?=...) (?!...) (?<=...) (?<!...)Flags (JS)
5 itemsCase-insensitive
iMultiline (^/$ per line)
mDot matches newline
sGlobal (all matches)
gUnicode
u