here is my string:
var str = \"This is my \\string\";
This is my code:
var replaced = str.replace(\"/\\\\/\", \"\\\\\\\\\")
The problem is that the \ in your first line isn't even recognized. It thinks the backslash is going to mark an escape sequence, but \s isn't an escape character, so it's ignored. Your var str is interpreted as just "This is my string". Try str.indexOf("\\")
- you'll find it's -1, since there is no backslash at all. If you control the content of str, do what David says - add another \ to escape the first.