var str = "/\test\test1\test.jpg";
如何在 JavaScript 中将 /\
替换为 \
?
最佳答案
首先,您应该使用附加的 \
转义 \
字符。正则表达式中的 /
也有同样的规则。
var str = "/\\test\\test1/\\test.jpg";
console.log('str is', str);
var res = str.replace(/\/\\/g, '\\')
console.log('res is', res);
关于javascript - 如何在 JavaScript 中替换/\with\,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41741310/