Regexp - Escape Character


The escape character in a regular expression is the backslash.

It's needed when the regular expression want to design a meta characters in a regular expression.


  • takes away any special meaning that the meta characters may have.
  • applies both inside and outside character classes.


For example, if you want to match:

  • the backslash itself, you write \\
  • a * character, you write \*

otherwise, they would be have be interpreted as meta-character

Php: Single and double quoted PHP strings have special meaning of backslash. Thus if \ has to be matched with a regular expression \\, then “\\\\” or '\\\\' must be used in PHP code.

Powered by ComboStrap