I Need to replace a set of characters from a string, I don't have control over the string so I can't just escape the +
symbol inside the string.
So my question is, seeing as this works if I change my value to 'breeding' it does replace the string. How can I escape a string without manually escaping them? I have tried
var s = "http://example.co/kb/tags/anazolic~racing~all+articles~breeding";
var value = 'all+articles';
var find = new RegExp('\~?\\b' + value + '\\b', 'g');
var l = s.replace(find, '');
console.log(l);
DEMO: http://jsfiddle.net/AnBc6/1/
I have also tried adding: value = encodeURIComponent(value);
but this didn't work either.
Any Help?