Javascript用一个正斜杠替换后退和斜线斜杠的组合 [英] Javascript replace a combination of back and forward slash with a single forward slash
问题描述
string.replaceAll(\\ /,/));
这是什么问题?我正在逃避转义字符,即反斜杠。
请指教。感谢
编辑:我有一个转义的URL,如http://www.gogobeans.com。我需要将其更改为 http://www.gogobeans.com
我从未听说过纯粹的javascript中的 replaceAll
方法,尝试替换
正则表达式:
string.replace(/ \\\\ // g,/ );
我已经使用 \\
然后转义范围字符 /
,它应该工作。
JSFiddle: 演示版
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
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
这篇关于Javascript用一个正斜杠替换后退和斜线斜杠的组合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!