问题
in Javascript, I am having some trouble replacing '/' with '/' in a string. I tried this
string.replaceAll("\\/","/"));
What's wrong with this ? I am escaping the escape character i.e. the backslash.
Please advise. Thanks Edit: I have an escaped URL such as http://www.gogobeans.com. I need to change this to http://www.gogobeans.com
回答1:
I've never heard of replaceAll
method in pure javascript, try replace
with a regex:
string.replace(/\\\//g, "/");
I've escaped the escape character with \\
then escaped the scope character /
, it should work.
JSFiddle: DEMO
来源:https://stackoverflow.com/questions/10507770/javascript-replace-a-combination-of-back-and-forward-slash-with-a-single-forward