在Chrome Web Inspector中尝试以下代码:
> "foo".replace("foo", "$'"); // dollar sign followed by single quote
< "" // wtf
最佳答案
您需要使用$$
,因为$
用于引用组
var replaced = "foo".replace("foo", "$$'");
snippet.log(replaced);
<!-- Provides the `snippet` object, see http://meta.stackexchange.com/a/242144/134069 -->
<script src="http://tjcrowder.github.io/simple-snippets-console/snippet.js"></script>
Reference
$$插入“ $”。
关于javascript - JavaScript String.replace()中带有替换字符串“$'”的错误?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/36441837/