Regular Expressions Cheat Sheet
by Dave Child (DaveChild) via cheatography.com/1/cs/5/
Regular Expressions Anchors
Regular Expressions Quantifiers
Regular Expressions Groups and Ranges
Start of string, or start of line in multi-line pattern
0 or more
Any character except new line (n)
Start of string
1 or more
a or b
End of string, or end of line in multi-line pattern
0 or 1
End of string
Passive (non-capturing) group
3 or more
Range (a or b or c)
Not word boundary
3, 4 or 5
Not a or b or c
Start of word
Add a ? to a quantifier to make it ungreedy.
Letter from a to q
End of word
Upper case letter from A to Q
Regular Expressions Escape Sequences
Digit from 0 to 7
Regular Expressions Character Classes
Escape following character
Begin literal sequence
Ranges are inclusive.
End literal sequence
Not white space
"Escaping" is a way of treating characters which have
Regular Expressions Pattern Modifiers
a special meaning in regular expressions literally,
rather than as special characters.
Treat string as single line
Allow comments and white space in pattern
Regular Expression Common Metacharacters
Regular Expressions POSIX
Upper case letters
Lower case letters
The escape character is usually the backslash - .
Digits and letters
Space and tab
Printed characters and spaces
Digits, letters and underscore
Regular Expressions Special Characters
Octal character xxx
Regular Expressions String Replacement
nth non-passive group
"xyz" in /^(abc(xyz))$/
"xyz" in /^(?:abc)(xyz)$/
Before matched string
After matched string
Last matched string
Entire matched string
Hex character hh
Some regex implementations use instead of $.
Regular Expressions Assertions
?!= or ?<!
Condition [if then]
Condition [if then else]
Dave Child (DaveChild)
This cheat sheet was published on 19th October, 2011
FeedbackFair, increase your conversion rate today!
and was last updated on 14th November, 2012.
Try it free!