Regex Cheatsheet
A comprehensive regex quick reference guide organized by category. Click any pattern to copy it to your clipboard. Perfect for developers who need to look up regex syntax quickly.
12Character Classes
.Any character except newline
c.t→cat, cut, cbt\dDigit (0-9)
\d+→123, 42, 0\DNon-digit
\D+→abc, xyz\wWord character (a-z, A-Z, 0-9, _)
\w+→hello_world\WNon-word character
\W→!, @, #\sWhitespace (space, tab, newline)
\s+→ , \t, \n\SNon-whitespace
\S+→hello[abc]Any of a, b, or c
[aeiou]→a, e, i, o, u[^abc]Not a, b, or c
[^aeiou]→b, c, d[a-z]Character range a to z
[a-z]+→hello[A-Z]Character range A to Z
[A-Z]+→HELLO[0-9]Digit range 0 to 9
[0-9]+→123458Anchors
^Start of string/line
^Hello→Hello at start$End of string/line
world$→world at end\bWord boundary
\bword\b→whole word only\BNon-word boundary
\Bword→password(?=...)Positive lookahead
\d+(?=px)→100 in "100px"(?!...)Negative lookahead
\d+(?!px)→100 in "100em"(?<=...)Positive lookbehind
(?<=\$)\d+→100 in "$100"(?<!...)Negative lookbehind
(?<!\$)\d+→100 in "100"9Quantifiers
*Zero or more
ab*c→ac, abc, abbc+One or more
ab+c→abc, abbc?Zero or one (optional)
colou?r→color, colour{n}Exactly n times
\d{3}→123{n,}n or more times
\d{2,}→12, 123, 1234{n,m}Between n and m times
\d{2,4}→12, 123, 1234*?Zero or more (lazy)
a.*?b→shortest match+?One or more (lazy)
a.+?b→shortest match??Zero or one (lazy)
a??b→shortest match6Groups & References
(...)Capturing group
(\d+)px→Group: 100(?:...)Non-capturing group
(?:ab)+→ababab(?<name>...)Named capturing group
(?<num>\d+)→Group "num"\1Backreference to group 1
(\w)\1→aa, bb, cc\k<name>Named backreference
\k<word>→References named group(a|b)Alternation (or)
(cat|dog)→cat or dog5Flags
gGlobal - find all matches
/\d/g→All digitsiCase insensitive
/hello/i→HELLO, HellomMultiline mode
/^line/m→Line startssDotall - . matches newline
/a.b/s→a\nbuUnicode support
/\u{1F600}/u→Emoji8Special Characters
\nNewline
line1\nline2→Two lines\rCarriage return
a\rb→ab\tTab
col1\tcol2→Two columns\0Null character
a\0b→a\0b\\Escaped backslash
\\n→Literal \n\.Escaped dot (literal)
3\.14→3.14\^Escaped caret (literal)
\^start→^start\$Escaped dollar (literal)
end\$→end$