Trying to find "\[" in my content don't get any results. I use this pattern:
preg_replace('/\\\[/', $content, $matches);
What's wrong whith my pattern? Thank you.
Update. My fault, I meant preg_match_all
.
Trying to find "\[" in my content don't get any results. I use this pattern:
preg_replace('/\\\[/', $content, $matches);
What's wrong whith my pattern? Thank you.
Update. My fault, I meant preg_match_all
.
preg_replace
is replacing all found matches. Use preg_match
for the first match and preg_match_all
to get all matches instead:
preg_match_all('/\\\[/', $content, $matches);
preg_replace('/\\\\[/', $content, $matches);
Try 4 (four) backslashes, because the pattern you get with three is "\[" which means just "[" to the regexp engine. :)
Try \\\\\\[
, should work.
Because those two characters have special meaning in regexp they have to be masked like this: \\\[
. Now when we are putting this regexp into a string for php every backslash has to be masked again because backslash has a special meaning in a string.