teguh123 wrote:Why is "" is different than ' in escaping regular expression?
It is different with respect to PHP. The problem is that there are two levels of interpretation at work here. At one level, the string is interpreted according to the rules for strings in PHP. At the next level, the interpreted PHP string is then interpreted as a regular expression pattern.
Single quoted PHP strings have fewer escape sequences, hence it is easier to work with them when you have these two levels of interpretation. Unfortunately, \ is an escape sequence for single quoted strings as well, so using them in this specific pattern does not make a difference.
teguh123 wrote:What I mean by \- is either \ (hence \) or - (hence -) should be turned into space.
To express a backslash in a regex pattern, you usually need to escape it with a backslash. To express a backslash in a PHP string, you also usually need to escape it with a backslash. Therefore, you should write '\\' to express a backslash.
Based on what you stated, the preceding forward slash should not be there. Therefore, you should write:
$Query404 = preg_replace('[\\\\-?]', ' ', $Query404);