Cheat Sheets

Regex Cheatsheet

Search and copy practical regex snippets, grouped by category with quick examples.
Search Regex Patterns

Character Classes

TitleDescriptionPatternExampleMatched
Any digitMatches a single digit 0-9.
\d
Order 424
Any non-digitMatches non-digit runs.
\D+
ABC! 123ABC!
Word character runMatches letters, digits, underscore.
\w+
user_name1 and _okuser_name1
WhitespaceMatches spaces, tabs, newlines.
\s+
line one\nline two

Anchors

TitleDescriptionPatternExampleMatched
Start of lineMatches Hello at the start.
^Hello
Hello worldHello
End of lineMatches world at the end.
world$
Hello worldworld

Quantifiers

TitleDescriptionPatternExampleMatched
Zero or moreo appears zero or more times.
go*gle
ggle google gooogleggle, google, gooogle
One or moreo appears one or more times.
go+gle
ggle google goooglegoogle, gooogle
Optionalu is optional.
colou?r
color colourcolor, colour
Exact rangeMatches numbers with length 2-4.
\d{2,4}
7 42 512 1000142, 512, 1000

Groups

TitleDescriptionPatternExampleMatched
Capturing groupCaptures repeated abc.
(abc)+
abcabc xyzabcabc
Non-capturing groupGroups protocol variants without capturing.
(?:https?)://\S+
http://a.com https://b.devhttp://a.com, https://b.dev
Named groupCaptures named parts.
(?<year>\d{4})-(?<month>\d{2})
2026-05 release2026-05

Lookarounds

TitleDescriptionPatternExampleMatched
Positive lookaheadWord before @ sign.
\w+(?=@)
hello@example.comhello
Negative lookaheadfoo not followed by bar.
foo(?!bar)
foo foobar foozfoo, foo
Positive lookbehindNumbers after dollar sign.
(?<=\$)\d+
$25 and $30025, 300
Negative lookbehindNumbers not preceded by -.
(?<!-)\d+
-10 20 -3 70, 20, 7

Flags

TitleDescriptionPatternExampleMatched
Global flagFinds all lowercase cat matches.
/cat/g
cat CAT catcat, cat
Ignore case flagMatches cat in any case (first match).
/cat/i
CAT cat cAtCAT
Multiline flag^ applies per line.
/^error/m
info\nerror\nwarnerror
Dotall flagDot can match newlines.
/a.b/s
a\nba\nb
Unicode flagUnicode letter matching.
/\p{L}+/u
naïve cafénaïve, café
Sticky flagMatches from current index only.
/\d+/y
123-45123

Escape Sequences

TitleDescriptionPatternExampleMatched
NewlineMatches a line break character.
\n
line1\nline2\n
TabMatches a tab character.
\t
A\tB\t
Word boundaryMatches cat as a full word.
\bcat\b
cat scatter catalogcat
Literal dotMatches an actual . character.
\.
v1.2.3., .
Literal backslashMatches \ in text.
\\
C:\\\\Tools\\\\Regex\\, \\, \\, \\

Common Patterns

TitleDescriptionPatternExampleMatched
EmailBasic email matcher.
\b[\w.%+-]+@[\w.-]+\.[A-Za-z]{2,}\b
hello@example.comhello@example.com
URL (http/https)Matches web URLs.
https?:\/\/[^\s]+
https://google.comhttps://google.com
Hex colorMatches 3 or 6-char hex colors.
#(?:[0-9a-fA-F]{3}){1,2}\b
#0ea5e9#0ea5e9
IPv4Matches IPv4 addresses.
\b(?:25[0-5]|2[0-4]\d|1?\d?\d)(?:\.(?:25[0-5]|2[0-4]\d|1?\d?\d)){3}\b
192.168.1.10192.168.1.10
Date (YYYY-MM-DD)Matches ISO-like calendar dates.
\b\d{4}-\d{2}-\d{2}\b
2026-05-282026-05-28