string.search() that ignores accented characters?

前端 未结 2 1643
醉话见心
醉话见心 2021-01-25 16:24

I need to treat accented characters as if they were the same as their non accented counterparts. This is my code:

var re = new RegExp(string, \'i\');
if(target.s         


        
2条回答
  •  我在风中等你
    2021-01-25 17:03

    I think you have to remove the accents first then do your RegExp.
    You can use this function taht I found here :

    function stripVowelAccent(str)
    {
     var rExps=[
     {re:/[\xC0-\xC6]/g, ch:'A'},
     {re:/[\xE0-\xE6]/g, ch:'a'},
     {re:/[\xC8-\xCB]/g, ch:'E'},
     {re:/[\xE8-\xEB]/g, ch:'e'},
     {re:/[\xCC-\xCF]/g, ch:'I'},
     {re:/[\xEC-\xEF]/g, ch:'i'},
     {re:/[\xD2-\xD6]/g, ch:'O'},
     {re:/[\xF2-\xF6]/g, ch:'o'},
     {re:/[\xD9-\xDC]/g, ch:'U'},
     {re:/[\xF9-\xFC]/g, ch:'u'},
     {re:/[\xD1]/g, ch:'N'},
     {re:/[\xF1]/g, ch:'n'} ];
    
     for(var i=0, len=rExps.length; i

提交回复
热议问题