Regex Cheat Sheet
Quick reference for regular expression syntax
Character Classes
.Match any character except newline\dMatch any digit (0-9)\DMatch any non-digit character\wMatch any word character (a-z, A-Z, 0-9, _)\WMatch any non-word character\sMatch any whitespace character\SMatch any non-whitespace character[abc]Match any character in the set[^abc]Match any character NOT in the set[a-z]Match any character in the rangeAnchors
^Match the start of the string$Match the end of the string\bMatch a word boundary\BMatch a non-word boundaryQuantifiers
*Match 0 or more times+Match 1 or more times?Match 0 or 1 time{n}Match exactly n times{n,}Match at least n times{n,m}Match between n and m times*?Match 0 or more (lazy)+?Match 1 or more (lazy)??Match 0 or 1 (lazy)Groups & Lookaround
(...)Capturing group(?:...)Non-capturing group(?=...)Positive lookahead(?!...)Negative lookahead(?<=...)Positive lookbehind(?<!...)Negative lookbehind\1, \2, etc.Backreference to group(?<name>...)Named capturing groupAlternation
a|bMatch either a or b(a|b)Group with alternationEscaped Characters
\.Match literal dot\\Match literal backslash\nMatch newline\rMatch carriage return\tMatch tab\uFFFFMatch Unicode character\xHHMatch hex characterFlags
gGlobal search (find all matches)iCase-insensitive searchmMulti-line mode (^ and $ match line boundaries)sDot-all mode (. matches newline)uUnicode modeySticky mode