我想替换字符串中所有出现的一个值为另一个值。
目前我已经有了以下代码:
var result = "Cooker Works"
var searchterm = "cooker wor";
searchterm.split(" ").forEach(function (item) {
result = result.replace(new RegExp(item, 'g'), "<strong>" + item + "</strong>");
});
console.log(result)
result = "<strong>Cooker</strong> <strong>Wor</strong>s";
我在处理这个案例时遇到了问题,有没有办法可以忽略它,仍然得到我想要的结果。