[英]javascript replacing escape chars
I am trying to replace all \\"
with "
from a string that is returned from xml response in javascript. 我试图从javascript中的xml响应返回的字符串中替换所有\\"
with "
。
For example: I have string my \\" string \\" is messedup in \\" xml
, the expected string is my " string " is messedup in " xml
例如:我有字符串my \\" string \\" is messedup in \\" xml
,期望的字符串是my " string " is messedup in " xml
I have tried strVariable= strVariable.replace("/\\\\\\"/g", '"');
我试过strVariable= strVariable.replace("/\\\\\\"/g", '"');
. 。 it does not work. 这是行不通的。 I have also tried strVariable= strVariable.replace("/\\"/g", '"');
我也试过strVariable= strVariable.replace("/\\"/g", '"');
This also does not work. 这也行不通。 Please let me know if I am missing something here. 如果我在这里遗漏了什么,请告诉我。
Use: 采用:
strVariable= strVariable.replace(/\\\"/g, '"');
Regex are consturcted without quotes 正则表达式是没有引号的
str = str.split('\\"').join('"');
The code will replace all \\"
with "
. 代码将替换所有\\"
with "
。
Edit : Sorry I forgot \\
编辑:对不起我忘了\\
Edit : Changed the code as per comments 编辑:根据评论更改代码
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.