Posix Regex Cheat Sheet



PCRE (Perl Compatible Regular Expressions) is a C library implementing regex. It was written in 1997 when Perl was the de-facto choice for complex text processing tasks. The syntax for patterns used in PCRE closely resembles Perl. PCRE syntax is being used in many big projects called flavors – .NET, Java, JavaScript, XRegExp, Perl, PCRE, Python, and Ruby, and the programming languages C#, Java, JavaScript, Perl, PHP, Python, Ruby, and VB.NET.
PCRE’s syntax is much more powerful and flexible than either of the POSIX regular expression flavors and than that of many other regular-expression libraries.
we’re focused on PRCE mostly unless stated!

Posix regex testExpressionRegex

Posix Regex Examples

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

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

Hidden chars or shortcuts

s = [ tnrf]
d = [0-9]
w = [a-zA-Z_0-9])

Sheet

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

Case Conversion

l Make next character lowercase
u Make next character uppercase
L Make entire string (up to E) lowercase
U Make entire string (up to E) uppercase
uL Capitalize first char, lowercase rest (sentence)

PCRE regex quick reference

[abx-z]One character of: a, b, or the range x-z
[^abx-z]One character except: a, b, or the range x-z
a|ba or b
a?Zero or one a’s (greedy)
a??Zero or one a’s (lazy)
a*Zero or more a’s (greedy)
a*?Zero or more a’s (lazy)
a+One or more a’s (greedy)
a+?One or more a’s (lazy)
a{4}Exactly 4 a’s
a{4,8}Between (inclusive) 4 and 8 a’s
a{9,}9 or more a’s
(?>…)An atomic group
(?=…)A positive lookahead
(?!…)A negative lookahead
(?<=…)A positive lookbehind
(?<!…)A negative lookbehind
(?:…)A non-capturing group
(…)A capturing group
(?P<n>…)A capturing group named n

Posix Regex Cheat Sheet 2019

POSIX PO pattern. Post Posting Guidelines. Match an email address Validate an ip address date format (yyyy-mm-dd) Url Validation Regex Regular Expression - Taha match whole word Match or Validate phone number nginx test Match html tag Blocking site with unblocked games. Character classes. Any character except. Regular Expressions Enjoy this cheat sheet at its fullest within Dash. Some regex implem­ent­ations use instead of $. POSIX :upper: Uppercase letters.

Perl Regex Cheat Sheet Pdf

^Beginning of the string
$End of the string
dA digit (same as [0-9])
DA non-digit (same as [^0-9])
wA word character (same as [_a-zA-Z0-9])
WA non-word character (same as [^_a-zA-Z0-9])
sA whitespace character
SA non-whitespace character
bA word boundary
BA non-word boundary
nA newline
tA tab
cYThe control character with the hex code Y
xYYThe character with the hex code YY
uYYYYThe character with the hex code YYYY
.Any character
YThe Y’th captured group
(?1)Recurse into numbered group 1
(?&x)Recurse into named group x
(?P=n)The captured group named ‘n’
(?#…)A comment