[英]How to split escape character \ in Javascript
The escape character is consumed when the string literal is parsed so there are no \\
characters in the string to replace.解析字符串文字时会使用转义字符,因此字符串中没有要替换的\\
字符。
It is too late to fix this programmatically.以编程方式修复此问题为时已晚。 You need to edit the original source code to represent \\
characters as \\\\
.您需要编辑原始源代码以将\\
字符表示为\\\\
。
You can't create a string like this, you have to use the double backslash.你不能创建这样的字符串,你必须使用双反斜杠。
var str = "..\..\common\core\services\shared.service";
console.log(str); // "....commoncoreservicesshared.service"
// Correct way
var str = "..\\..\\common\\core\\services\\shared.service";
console.log(str); // "..\..\common\core\services\shared.service"
// Then use this:
str.replace(/\\/g, '/');
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.