Pcre Regex Cheat Sheet



RegexSheetsPcre Regex Cheat Sheet

Create regular expressions with natural, human language. Cheat Sheet: Full documentation available here. Match 'hello world' matches 'hello world' exactly match 'hello' then optionally ' world' matches 'hello' or 'hello world' match 'hello' or 'world' matches 'hello' or 'world' match a word matches any word. Regular Expression Tester with highlighting for Javascript and PCRE. Quickly test and debug your regex. Toggle navigation. RegEx Testing From Dan's Tools. HTML/JS/CSS Playground. Top Regular Expressions. Match string not containing string. Character classes. Any character except newline w d s: word, digit, whitespace. Regular Expression Flags; i: Ignore case: m ^ and $ match start and end of line: s. Matches newline as well: x: Allow spaces and comments: J: Duplicate group names allowed: U: Ungreedy quantifiers (?iLmsux) Set flags within regex. No Comments on Regex: Pattern Modifiers Cheat Sheet; g: Global match: i. Case-i­nse­nsitive: m. Multiple lines: s. Treat string as single line: x. Allow comments and whitespace in pattern: e. Evaluate replac­ement: U. Ungreedy pattern. PCRE modifier. Tags Regex Cheat Sheet. Regular Expressions Cheat Sheet by Dave Child (DaveChild) via cheatography.com/1/cs/5/ Anchors ^ Start of string, or start of line in multi-line pattern.

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

Pcre Regex Cheat Sheet Download

Pcre Regex Cheat Sheet

Pcre Cheat Sheet

Made by Dave Child