|
Document Title |
Programming Perl Regular Expression Quick Reference Guide |
|
Type |
Quick Reference |
|
Categories |
Quick Reference, programming |
|
Level |
N/A |
|
Keywords |
quick reference programming perl php regular expression regex regexp |
|
Author |
Stewart Watkiss www.watkissonline.co.uk |
|
Date Created |
8th September 2009 |
|
Last Updated |
8th September 2009 |
|
Copyright |
© 2009 www.penguintutor.com |
This is a quick reference guide to some of the most common special characters used in regular expression matching. This is based on perl regular expressions, which are also used in php using preg_match.
\s White space [\t\n\r\f]
\S Not white space [^\t\n\r\f]
\d Digit [0-9]
\D Not digit [^[0-9]
\w Word character [a-zA-Z_0-9]
\W Nonword character e.g. [^a-zA-Z_0-9]
* 0 or more
*? 0 or more, not greedy
+ 1 or more
+? 1 or more, not gready
? 0 or 1
?? 0 or 1, not gready
{x} Exactly x times
{x,y} Between x and y times
{x,y} Between x and y times, not gready
^ At the beginning of the string
$ At the end of the string
\ Escape chracter
\n New line
\r Carriage return
\t Tab
$n Bracketted group (n is which group) – non passive
$` Before matched string
$' After matched string
$+ Last matched string
$& Entire matched string
$_ Entire input string
$$ Literal $
. Any character except \n
(a|b) a or b
(...) Group
(?:...) Passive group
[abc] a, b or c
[^abc] not a or b or c
[a-c] Any letter from a to c
[A-C] Any upper case letter A to C
[0-5] Any digit 0 to 5
g Global match (multiple)
i Case-insensitive
m Multiple lines
s Treat string as single line
U Ungreedy pattern
^ [ . $ { * ( )
\ + | ? < >