I have a string where 2 backslashes must become 3 backslashes. With all the escaping of backslashes, I can't do it and nothing's working.
For example:
-
aaaaa\\aaaaa
must becomeaaaaa\\\aaaaa
-
aaaaa\\\aaaaa
STAYSaaaaa\\\aaaaa
(2 backslashes in a row must not be detected)
I managed this, which works in regex101.com:
(\\\\)([^\\])
so in php, it would be:
preg_replace('/(\\\\)([^\\])/', '\\\$2', $bob);
But php gives me this error message:
preg_replace(): Compilation failed: missing terminating ] for character class at offset 10
So I don't know if it's a bug of PHP, but I need another way of doing this and I can't find the solution on google.