【发布时间】:2016-07-05 05:20:52
【问题描述】:
我想从字符串中替换所有存在的字符,但它不起作用。这是我的代码:
$.each(jsonArray, function (fromString, jtm) {
// tempString = tempString.replace(jtm.from, jtm.to)
tempString = tempString.replaceAll(jtm.from, jtm.to);
});
我检查了使用 global 将所有替换为 Told in this article,但我不知道如何在我的代码中实现。
请帮助我。
【问题讨论】:
-
tempString = tempString.replace(new RegExp(jtm.from,'g'), jtm.to) -
tempString = tempString.replace(new RegExp(jtm.from.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&'),'g'), jtm.to)
标签: jquery arrays json string replace