RegEx Cheatsheet Generator
Basic Patterns
.
Any character except newline
Example: a.c matches 'abc', 'a1c'
\
Escape special characters
Example: \. matches '.'
^
Start of string/line
Example: ^abc matches 'abc' at start
$
End of string/line
Example: abc$ matches 'abc' at end
Quantifiers
*
0 or more occurrences
Example: ab* matches 'a', 'ab', 'abb'
+
1 or more occurrences
Example: ab+ matches 'ab', 'abb'
?
0 or 1 occurrence
Example: ab? matches 'a', 'ab'
{n}
Exactly n occurrences
Example: a{3} matches 'aaa'
{n,}
n or more occurrences
Example: a{2,} matches 'aa', 'aaa'
{n,m}
Between n and m occurrences
Example: a{2,3} matches 'aa', 'aaa'
Character Classes
[abc]
Any character in the set
Example: [abc] matches 'a', 'b', 'c'
[^abc]
Any character not in the set
Example: [^abc] matches 'x', 'y'
[a-z]
Any character in the range
Example: [a-z] matches lowercase letters
\w
Word character [A-Za-z0-9_]
Example: \w matches 'a', '1', '_'
\d
Digit [0-9]
Example: \d matches '0' to '9'
\s
Whitespace character
Example: \s matches space, tab