如何在字符串中替换反斜杠双引号?

ray*_*ray 1 javascript

如何在字符串中替换反斜杠双引号(例如\“)?

下面的代码不起作用。

<!DOCTYPE html>
<html>
<head>
</head>
    <script type="text/javascript">

        var myVar = '\"Things You Should Know\"';
        document.write(myVar.replace(/\\\"/g, '|'));
    </script>
<body>
<br>hello
</body>
</html>
Run Code Online (Sandbox Code Playgroud)

Hor*_*ren 5

var myVar = '\"Things You Should Know\"';
document.write(myVar.replace(/\"/g, '|'));
Run Code Online (Sandbox Code Playgroud)

\转义下一个字符,以便您的字符串只读取"Things You Should Know"