PHP preg_replace

php, preg-replace, regex

Solution

Use 4 backslashes and please don't forget the delimiters:

`echo echo preg_replace('~\\\\~','\\\\\\\\','text to \\ be parsed');`

Online demo

Explanation: When PHP parse `\\\\` it will escape `\\` two times, which means it becomes `\\`, now when PHP passes it to the regex engine, it will receive `\\` which means `\`.

Problem

I use netbeans, I try to replace `\` with `\\` but it fails , it can't escape the `\\` character. This is not a Netbeans issue , it's a PHP issue . ``` preg_replace('\','\\','text to \ be parsed'); ``` Any sollutions?

Original source