Craig Francis


PCRE RegEx syntax

My notes on a single page, based on the information at php.net.

  Escape sequences
\d any decimal digit
\D any character that is not a decimal digit
\h any horizontal whitespace character
\H any character that is not a horizontal whitespace character
\s any whitespace character
\S any character that is not a whitespace character
\v any vertical whitespace character
\V any character that is not a vertical whitespace character
\w any "word" character
\W any "non-word" character
 
\b word boundary
\B not a word boundary
\A start of subject (independent of multiline mode)
\Z end of subject or newline at end (independent of multiline mode)
\z end of subject (independent of multiline mode)
\G first matching position in subject
  Explication
(?:red|white) Non-capturing sub pattern
(sens|respons)e and \1ibility Back reference
foo(?=bar) Positive lookahead assertion
foo(?!bar) Negative lookahead assertion
(?<=foo)bar Positive lookbehind assertion
(?<!foo)bar Negative lookbehind assertion
(?(condition)yes-pattern) Conditional subpattern
(?(condition)yes-pattern|no-pattern) Conditional subpattern
  Internal option letters
i for PCRE_CASELESS
m for PCRE_MULTILINE
s for PCRE_DOTALL
x for PCRE_EXTENDED
U for PCRE_UNGREEDY
X for PCRE_EXTRA
J for PCRE_INFO_JCHANGED