小编Reg*_*xme的帖子

重音不敏感的正则表达式

我的代码:

jQuery.fn.extend({
 highlight: function(search){
  var regex = new RegExp('(<[^>]*>)|('+ search.replace(/[.+]i/,"$0") +')','ig');

  return this.html(this.html().replace(regex, function(a, b, c){
   return (a.charAt(0) == '<') ? a : '<strong class="highlight">' + c + '</strong>';
  }));
 }

});
Run Code Online (Sandbox Code Playgroud)

我想突出显示带重音的字母,即:

$('body').highlight("cao");
Run Code Online (Sandbox Code Playgroud)

应突出显示:[ção] OR [çÃo] OR [cáo] OR expre [cão] tion或[Cáo] tion

我怎样才能做到这一点?

regex unicode jquery highlight diacritics

8
推荐指数
1
解决办法
2439
查看次数

标签 统计

diacritics ×1

highlight ×1

jquery ×1

regex ×1

unicode ×1