RegEx - Why not 3 backslashes instead of 4 to escape a backslash

Little thing that has been bothering me for a while, why does everywhere I look claim you need 4 backslashes to match a single backslash in a regular expression, when 3 works just fine??? Even the PHP manual says you need 4. http://www.php.net/manual/en/regexp.reference.backslash.php

For Example…


$string = 'c:\	his\\is\\a\	est';

$new_string = preg_replace("#\\\\\\#", '/', $string);

echo "<p> new_string: $new_string </p>";

Outputs: new_string: c:/this/is/a/test

Am I missing something?

It depends what comes after the backslash.
if you have "\\
" it might be seen as “\[newline]”

You have to remember, you are not only escaping for PHP but also for PREG.