一个兼容大小写,特殊字符的高亮显示函数
function highlight(str, char) { const escapedChar = char.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); if (str.toLowerCase().includes(char.toLowerCase())) { return str.replace(new RegExp(escapedChar, 'gi'), `<mark>$&</mark>`); } else { return str; } }
标签:高亮,显示字符,兼容,char,大小写,str,特殊字符 From: https://www.cnblogs.com/anin/p/17390956.html