Regex Cheatsheet

Interactive regex cheatsheet where you can click patterns to test them live

regexcheatsheetreferencepatternguide

Live Regex Tester

//
3 matches
Hello 42 World 2024, regex is fun with 3 numbers!

Showing 56 of 56 entries

Character Classes

PatternDescription
.Any character except newline
\wWord character: [a-zA-Z0-9_]
\WNon-word character
\dDigit: [0-9]
\DNon-digit character
\sWhitespace: space, tab, newline
\SNon-whitespace character
[abc]Character in set a, b, or c
[^abc]Character not in set
[a-z]Character in range a through z
[A-Z]Character in range A through Z
[0-9]Digit character (same as \d)
[a-zA-Z]Any letter (upper or lower)

Anchors

PatternDescription
^Start of string (or line in multiline mode)
$End of string (or line in multiline mode)
\bWord boundary
\BNon-word boundary
\AAbsolute start of string (not affected by multiline)
\ZAbsolute end of string

Quantifiers

PatternDescription
*Zero or more of the preceding element
+One or more of the preceding element
?Zero or one of the preceding element (optional)
{n}Exactly n repetitions
{n,}At least n repetitions
{n,m}Between n and m repetitions (inclusive)
*?Lazy: zero or more (as few as possible)
+?Lazy: one or more (as few as possible)
??Lazy: zero or one (prefer zero)
{n,m}?Lazy version of bounded quantifier

Groups & References

PatternDescription
(abc)Capturing group: captures the match
(?:abc)Non-capturing group: groups without capturing
(?<name>abc)Named capturing group
\1, \2Backreference to captured group 1, 2, etc.
\k<name>Backreference to named group
|Alternation: matches either expression

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 (not just first)
iCase-insensitive matching
mMultiline: ^ and $ match start/end of each line
sDotall: . matches newline characters too
uUnicode: treat pattern as Unicode code points
ySticky: match only from lastIndex position
dIndices: return start/end indices of matches

Special Characters

PatternDescription
\nNewline character
\tTab character
\rCarriage return
\0Null character
\uXXXXUnicode character by hex code point
\xHHASCII character by hex value
\\Literal backslash
\.Literal dot (escaping special char)
\(Literal parenthesis
\[Literal bracket