.*
REFERENCE

Regex Cheatsheet

A complete reference for regular expression syntax. Bookmark this page — you'll come back to it.

Character Classes

PatternDescription
.Any character except newline
\dAny digit (0-9)
\DAny non-digit
\wWord character (letter, digit, underscore)
\WNon-word character
\sAny whitespace (space, tab, newline)
\SAny non-whitespace
[abc]Any one of a, b, or c
[^abc]Any character except a, b, or c
[a-z]Any character in range a to z
[0-9]Any digit (same as \d)

Quantifiers

PatternDescription
*Match 0 or more times (greedy)
+Match 1 or more times (greedy)
?Match 0 or 1 time (optional)
{n}Match exactly n times
{n,}Match n or more times
{n,m}Match between n and m times
*?Match 0 or more times (lazy)
+?Match 1 or more times (lazy)
??Match 0 or 1 time (lazy)

Anchors & Boundaries

PatternDescription
^Start of string (or line with m flag)
$End of string (or line with m flag)
\bWord boundary
\BNon-word boundary

Groups & Backreferences

PatternDescription
(abc)Capturing group
(?:abc)Non-capturing group
(?<name>abc)Named capturing group
\1Backreference to group 1
\k<name>Named backreference
(a|b)Alternation (OR)

Lookahead & Lookbehind

PatternDescription
(?=abc)Positive lookahead — followed by abc
(?!abc)Negative lookahead — NOT followed by abc
(?<=abc)Positive lookbehind — preceded by abc
(?<!abc)Negative lookbehind — NOT preceded by abc

Flags

PatternDescription
gGlobal — find all matches
iCase-insensitive
mMultiline — ^ and $ match line boundaries
sDotall — . matches newlines too
uUnicode mode
vUnicode sets (extended)
dGenerate indices for matches
ySticky — match from lastIndex only

Special Characters

PatternDescription
\nNewline
\rCarriage return
\tTab
\0Null character
\\Literal backslash
\.Literal dot
\[Literal opening bracket