0
请看这JsFiddle。JavaScript的正则表达式不区分大小写
var target = "Thanks For Looking This Problem";
var phrase = ["anks", "for", "king T"];
for(var indx = 0; indx < phrase.length; indx ++)
{
target = target.replace(new RegExp(phrase[indx], "gi"), "~~~" + phrase[indx]+ "```");
}
我得到这样的输出:Th~~~anks``` ~~~for``` Loo~~~king T```his Problem
但我需要这样的输出:Th~~~anks``` ~~~For``` Loo~~~king T```his Problem
'对于' 而不是 '为'
谢谢。学习正则表达式的任何好的教程。因为我无法在Google搜索中找到您的方法。 – user10
链接的文档解释了替换语法。要学习在JS中使用正则表达式,您可以阅读[MDN指南](https://developer.mozilla.org/en-US/docs/JavaScript/Guide/Regular_Expressions),学习正则表达式语法(以及更多) http://www.regular-expressions.info/ – Bergi
感谢您的链接.... – user10