0
我想用粗体字符串替换字符串的匹配部分。用粗体字符串替换部分匹配的字符串
const str = 'This is an Example';
const term = 'exam';
现在我想获得的结果
This is an <strong>Exam</strong>ple
我试图用一个正则表达式,但接缝处有一个错误的语法也与此例中的大写将被忽略:
const result = str.replace(new RegExp(escapeRegExp(term), 'g'), '<strong>' + term + '</strong>');
使用标志'gi',不仅'g'。什么'escapeRegExp'返回? – Xufox