I have seen a lot of duplicates but none of them works
I spend a day to get this thing up. Gone through all duplicates
I need to replace a single backslash with a double backslash.
I am able to replace all other characters with a double backslash.
console.log("hello & 100\|".replace(/([&%$#_{}])/g, "\\"));
I know that two backslashes is indeed used to make a single backslash.
I tried all the possible ways of using regex as well. But neither works.
Here is another snippet I am using.
var replaceableString = "A\B";
replaceableString = replaceableString.replace(/\\/g, "\\\\");
console.log(replaceableString);
Unfortunately, this also is not working.
Please share if there are any workarounds.