Show Menu
Cheatography

My Regex Cheat Sheet (DRAFT) by

My Personal Regex cheatsheet

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Anchors

^
Start of line
$
End of line
\b
Word boundary
\B
Not word boundary

Special Character

\c
Control Character
\x
Hexade­cimal
\O
Octal
\n
Newline (OS neutral)
\r
Carriage Return
\t
Tab
\f
Form Feed
\Q
Begin literal sequence
\E
End literal Sequence

Assertions

?=
Positive Lookahead
?!
Negative Lookahead
?<=
Positive Lookbehind
?!= or ?<!
Negative Lookbehind
 

Quanti­fiers

*
0 or more
{3}
Exactly 3
+
1 or more
{3,}
3 or more
?
0 or 1
{3,5}
3, 4, or 5
Add a ? to a quantifier to make it ungreedy

Character Classes

\s
[ \t\n\r\f]
Whitespace
\S
[^ \t\n\r\f]
Not whitespace
\d
[0-9]
Digit
\D
[^0-9]
Not digit
\w
[a-zA-­Z0-9_]
Word
\W
[^a-zA­-Z0-9_]
Not word
 

Metach­ara­cters

.
Match any one character (except \n)
|
Alteration OR
( )
Group and Capture
[ ]
Define character class
\
Escape next character

Groups and Ranges

(a|b)
a or b
[abc]
Range (a or b or c)
[^abc]
Not (a or b or c)
[a-z]
Lower case alphachar
[a-z,A-Z]
Case-i­nse­nsitive alphachar
[0-9,a­-f,A-F]
Hexade­cimal range
Ranges are inclusive.