PCRE Quick Reference (Advanced)
| Previous Microplanet Gravity Next |
| (?-i) | set case sensitivity |
| (?i) | turn OFF case sensitivity after (?-i) |
| ^ | start of line or negates character class |
| $ | end of line |
| . | match any character |
| ? | 0 or 1 quantifier |
| * | 0 or more quantifier ( "*?" is ungreedy) |
| + | 1 or more quantifier ( "+?" is ungreedy) |
| {8} | Repetition: match exactly 8 |
| {3,} | Repetition: match three or more |
| {2,4} | Repetition {minimum,maximum} Example matches 2, 3, or 4 repetitions |
| NO (a number MUST come before the comma) | |
| \s | any whitespace character |
| \S | NOT a whitespace character |
| \d | any decimal digit |
| \D | NOT a decimal digit |
| \w | any "word" character |
| \W | any "NON-word" character |
| \b | word boundary |
| \B | NOT a word boundary |
| \ | general escape character with several uses |
| \\ | backslash character |
| ( ) | start and end of subpattern |
| { | start quantifier |
| (?= | start of positive lookahead assertion |
| (?! | start of negative lookahead assertion |
| (?<= | start of positive lookbehind assertions |
| (?<! | start of negative lookbehind assertions |
\w word: a letter, digit, or underscore character
| POSIX CHARACTER NOTATION - see examples | |
| alnum | letters and digits |
| alpha | letters |
| ascii | character codes 0 - 127 |
| blank | space or tab only |
| digit | decimal digits (same as \d) |
| graph | printing characters, excluding space |
| lower | lower case letters |
| upper | upper case letters |
| printing characters, including space | |
| punct | printing characters, excluding letters and digits |
| space | white space (not quite the same as \s) |
| word | "word" characters (same as \w) |
| Metacharacters:
Outside square brackets: \ ^ $ . [ | ( ) ? * + { Inside square brackets ("character class") \ ^ - [ ] (Any non-alphanumeric character can be escaped) POSIX Notation (inside Character Classes) POSIX uses names enclosed by [: and :] within the enclosing square brackets. Note: to use [[:upper:]] or [[:lower:]], also use (?-i) POSIX Examples [01[:alpha:]%] matches "0", "1", any alphabetic character, or "%" [12[:^digit:]] matches "1", "2", or any non-digit. Assertions Lookahead assertions start with (?= for positive assertions and (?! for negative assertions. \w+(?=;) matches a word followed by a semicolon, but does not include the semicolon in the match foo(?!bar) matches any occurrence of "foo" that is not followed by "bar" Lookbehind assertions start with (?<= for positive assertions and (?<! for negative assertions. (?<!foo)bar finds an occurrence of "bar" that is not preceded by "foo" |