string.search()忽略重音字符? [英] string.search() that ignores accented characters?
本文介绍了string.search()忽略重音字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要将重音字符视为与非重音字符相同。这是我的代码:
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.search(re) == 0) { }
目前忽略在角色的情况下,我如何忽略角色的重音?
It currently ignores the character's case, how do I also ignore if the character is accented or not?
推荐答案
我认为你必须删除重音符号首先做你的RegExp。
您可以使用此功能,我发现此处:
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<len; i++)
str=str.replace(rExps[i].re, rExps[i].ch);
return str;
}
这篇关于string.search()忽略重音字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文