如何用javascript 实现 regex match 忽略accents


function prepareHighLightWord(word){
 word=word.replace(/a/ig,'[aáàäâÄ]');
 word=word.replace(/e/ig,'[eéèëêÈÉÊË]');
 word=word.replace(/o/ig,'[oôöÖÕÔ]');
 word=word.replace(/i/ig,'[iiïîÌÌ]');
 word=word.replace(/u/ig,'[uüûÜÛ]');
 word=word.replace(/c/ig,'[cç]');
 word=word.replace(/y/ig,'[yÿý]');
 return word;
}
var searchString="..."
var matchString="...";
var word=prepareHighLightWord(string);
var pattern = new RegExp('('+word+')', ['gi']);
var rs = '$1';
var newString=searchString.replace(pattern, rs);

这是一个简单的例子。

评论

热门博文