Regex Cheat Sheet PDF


Regex Cheat Sheet PDF - wivato


Regular Expressions Cheat Sheet PDF

 The tables below are a reference to basic regex, A quick reference for regular expressions (regex), including symbols, ranges, grouping, assertions and some sample patterns to get you started.



Character Classes

 The character classes operators allow you to match characters inside a category (class). These operators offer their negations, which are the same as the normal operator but in upper case.

\c Control character
\s Whitespace character
\S Not whitespace character
\w Word
\W Not word
\d Digit
\D Not digit
\O Octal digit
\x Hexadecimal digit


Anachors

^ Start of string, or start of line depending on multiline mode
\A Beginning of string
$ End of string, or end of line depending on multiline mode
\Z End of string
\b Word boundary
\B Not word boundary
\< Start of word
\> End of word

Quantifiers

* 0 or more
+ 1 or more
? 0 or 1
\w Exactly 3
{3,} 3 or more
{3,6} Between 3 and 6

Assertions

?= Lookahead assertion
?! Negative lookahead
?<= Lookbehind assertion
?!= or ?<! Negative lookbehind
?> Once-only Subexpression
?() Condition [if then]
?()| Condition [if then else]
?# Comment

Escape Sequences

\ Escape following character
\Q Begin literal sequence
\E End literal sequence

POSIX

[:alpha:] Letters A-Z and a-z
[:alnum:] Digits and letters
[:punct:] Punctuation mark
[:upper:] Upper case letters
[:lower:] Lower case letters
[:digit:] Digits
[:xdigit:] Hexadecimal digits
[:blank:] Space and tab
[:cntrl:] Control characters
[:graph:] Printed characters
[:print:] Printed characters
[:word:] Digits, letters and underscore
[:space:] Blank characters


Special Characters

\n Letters A-Z and a-z
\r Carriage return
\v Vertical tab
\f Form feed
\xxx Octal character xxx
\xhh Hex character hh


String Replacement

$n nth non-passive group
$1 "xyz" in /^(?:abc)(xyz)$/
$2 "xyz" in /^(abc(xyz))$/
$` Before matched string
$' After matched string
$+ Last matched string
$& Entire matched string


Pattern Modifiers

i * Case-insensitive
(a|b) a or b
m * Multiple lines
s * Treat string as single line
[abc] Range (a or b or c)
x * Allow comments and whitespace in pattern
g Global match
U * Ungreedy pattern
e * Evaluate replacement


Groups and Ranges

. Any character except line break
(...) Group
(?:...) Passive (non-capturing) group
[^abc] Not (a or b or c)
[a-q] Lower case letter from a to q
[A-Q] Upper case letter from A to Q
[0-6] Digit from 0 to 6
\x Group/subpattern number "x"


Regex - Download This Cheat Sheet (PDF)







Font Size
+
16
-
lines height
+
2
-