PCRE Metacharacter Reference

    

Metacharacters have special meanings. To match a literal metacharacter (the actual character), you must escape the character with a backslash (\). To escape a backslash, use two (\\).
For example, a dot (.) in PCRE means "match any character." But if we want to match a dot and not any character, we write " \. " (without the quotes). To escape and match a backslash, use two (\\).

Quick ReferenceOutside square brackets, the metacharacters are as follows:
\ ^ $ . [ | ( ) ?  * + {
Inside square brackets (a "character class") the metacharacters are:
\ ^ - [ ]     (dash depends on the position in the enclosing brackets)

If in Doubt ..

From the manual: .. it is always safe to precede a non-alphanumeric with backslash to specify that it stands for itself.

Ø    In other words, if the character is not a number or letter, it does no harm to escape the character if you are not sure.

Metacharacter Descriptions
There are two different sets of metacharacters: those that are recognized anywhere in the pattern except within square brackets, and those that are recognized within square brackets.
Outside square brackets, the metacharacters are as follows:
  \      general escape character with several uses   ^      assert start of string   $      assert end of string   .      match any character except newline (by default)   [      start character class definition   |      start of alternative branch   (      start subpattern   )      end subpattern   ?      extends the meaning of (          also 0 or 1 quantifier          also quantifier minimizer   *      0 or more quantifier   +      1 or more quantifier          also "possessive quantifier"   {      start min/max quantifier
Part of a pattern that is in square brackets is called a "character class". In a character class the only metacharacters are:
  \      general escape character   ^      negate the class, but only if the first character   -      indicates character range   [      POSIX character class (only if followed by POSIX syntax)   ]      terminates the character class