Regex Cheatsheet
The regex syntax used across JavaScript, Python, and most modern languages - character classes, quantifiers, anchors, and groups.
Character classes
.Any character except newline
\dAny digit (0-9)
\DAny non-digit
\wWord character (letter, digit, underscore)
\WNon-word character
\sWhitespace (space, tab, newline)
[abc]Any of a, b, or c
[^abc]Any character except a, b, or c
[a-z]Any lowercase letter
Quantifiers
*0 or more of the preceding token
+1 or more of the preceding token
?0 or 1 of the preceding token
{n}Exactly n occurrences
{n,}n or more occurrences
{n,m}Between n and m occurrences
Anchors & boundaries
^Start of string (or line, with m flag)
$End of string (or line, with m flag)
\bWord boundary
\BNot a word boundary
Groups & flags
(abc)Capture group
(?:abc)Non-capturing group
(?<name>abc)Named capture group
a|bMatch a or b
gFlag: global - find all matches
iFlag: case-insensitive
mFlag: multiline - ^ and $ match line boundaries