I try to replace all occurences of \
in a string, but I can't find the way, even after searching on the web and here.
This is what I tried :
$ node
> var x = 'foo\bar\base'
> x.replace(/\\/g, '/');
'foo\bar\base'
I expect foo/bar/base
but the string is unchanged.
Same thing with split()
:
> x.split('\\')
[ 'foo\bar\base' ]
Context: this is from the DOM, I get this string with
var node = document.querySelector(sel);
node.innerText.replace(/\\/g, '/');
Edit there's a confusion between my try in nodejs and what I can have in real browser, check @Jeffrey Westerkamp comment in this answer