string.search() that ignores accented characters?

前端 未结 2 1613
醉话见心
醉话见心 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

    uses the library semplice

    http://semplicewebsites.com/removing-accents-javascript

    var latin_map = {
      'Á': 'A', // LATIN CAPITAL LETTER A WITH ACUTE
      'Ă': 'A', // LATIN CAPITAL LETTER A WITH BREVE
    ...
      'ᵥ': 'v', // LATIN SUBSCRIPT SMALL LETTER V
      'ₓ': 'x', // LATIN SUBSCRIPT SMALL LETTER X
    };
    
    
    String.prototype.latinise = function() {
       return this.replace(/[^A-Za-z0-9]/g, function(x) { return latin_map[x] || x; })
    };
    

提交回复
热议问题