javascript替换和斜杠

javascript替换和斜杠,javascript,replace,Javascript,Replace,我有一条线可以在一条线上翻转所有的斜线,效果很好 **flipSlashes = shortLocString.replace(/\\/g,"/");** 但如果我想把它们翻回去,它就会分崩离析。我已经尝试了以下所有方法。我不太清楚//g语法,所以不知道如何解决它 **flipSlashes = shortLocString.replace(///g,"\\");** **flipSlashes = shortUrlString.replace(/'/'/g,"\\")

我有一条线可以在一条线上翻转所有的斜线,效果很好

    **flipSlashes = shortLocString.replace(/\\/g,"/");**
但如果我想把它们翻回去,它就会分崩离析。我已经尝试了以下所有方法。我不太清楚//g语法,所以不知道如何解决它

    **flipSlashes = shortLocString.replace(///g,"\\");**
    **flipSlashes = shortUrlString.replace(/'/'/g,"\\");**
    **flipSlashes = shortUrlString.replace(///g,"\\");**
感谢您的帮助, dp

使用(即/在正则表达式中必须使用\/转义)

flipSlashes=shortLocString.replace(//\//g,“\\”)

使用(即/在正则表达式中必须使用\/转义)


flipSlashes=shortLocString.replace(//\//g,“\\”)

这将为您提供两种方法

var shortLocString = "a/b//c/d//e///f////";
var shortLocString1 = shortLocString.replace(/\//g,"\\");
var shortLocString2 = shortLocString1.replace(/\\/g,"/");

这将给你两种方法

var shortLocString = "a/b//c/d//e///f////";
var shortLocString1 = shortLocString.replace(/\//g,"\\");
var shortLocString2 = shortLocString1.replace(/\\/g,"/");

太棒了,工作得很有魅力!非常感谢!我需要仔细研究一下这个语法。但我认为这是有道理的。太棒了,工作得很有魅力!非常感谢!我需要仔细研究一下这个语法。但我认为这是有道理的。