PHP preg正则表达式模式

  1. What does this pattern '/\\\(?!&#|\?#)/' match in PHP preg_replace function?
  2. Is this pattern valid?
  3. Why there are 3 backslashes in a row \\\?
  1. The pattern checks for a literal backslash not followed by &# or ?#.
  2. Yes.
  3. Because it's written as a PHP string literal. '\\' (an escaped escape character) in a string literal resolves to the actual string '\', so the actual regular expression is /\\(?!&#|\?#)/. The backslash is escaped inside the regex so it does not escape the (. So the actual pattern looked for is \&# or \?#.