C++ Regex Cheat Sheet

broken image


Regular Expressions (Regex) Character Classes Cheat Sheet POSIX Character Classes for Regular Expressions & their meanings. RegexPal also provides you with a larger list of regex examples as well as a regex cheat sheet for reference. If you're using regex in a web project and would like a quick reference to the regex tokens available, use the regex cheat sheet above as well the tools mentioned to help simplify the regex expression building process.

Regular Expression Cheat Sheet Pdf

Expressions

Regular Expression Sheet

Anchors

Start of string, or start of line in multi-line pattern
Start of string
End of string, or end of line in multi-line pattern
End of string
Word boundary
Not word boundary
Start of word
End of word

Character Classes

Control character
White space
Not white space
Digit
Not digit
Word
Not word
Hexade­cimal digit
Octal digit

POSIX

Upper case letters
Lower case letters
All letters
Digits and letters
Digits
Hexade­cimal digits
Punctu­ation
Space and tab
Blank characters
Control characters
Printed characters
Printed characters and spaces
Digits, letters and underscore

Assertions

Lookahead assertion
Negative lookahead
Lookbehind assertion
Negative lookbehind
Once-only Subexp­ression
Condition [if then]
Condition [if then else]
Comment

Quanti­fiers

0 or more
Exactly 3
1 or more
3 or more
0 or 1
3, 4 or 5

Escape Sequences

Escape following character
Begin literal sequence
End literal sequence
'­Esc­api­ng' is a way of treating characters which have a special meaning in regular expres­sions literally, rather than as special charac­ters.

Common Metach­ara­cters

[
$
*
)
?
>

Special Characters

New line
Carriage return
Tab
Vertical tab
Form feed
Octal character xxx
Hex character hh

Groups and Ranges

Any character except new line (n)
a or b
Group
Passive (non-c­apt­uring) group
Range (a or b or c)
Not (a or b or c)
Lower case letter from a to q
Upper case letter from A to Q
Digit from 0 to 7
Group/­sub­pattern number '­x'

Pattern Modifiers

Global match
Case-i­nse­nsitive
Multiple lines
Treat string as single line
Allow comments and whitespace in pattern
Evaluate replac­ement
Ungreedy pattern

String Replac­ement

nth non-pa­ssive group
'­xyz­' in /^(abc­(xy­z))$/
'­xyz­' in /^(?:a­bc)­(xyz)$/
Before matched string
After matched string
Last matched string
Entire matched string

C++ Regex Cheat Sheet

Made by Dave Child





broken image