在正则表达式中忽略重音 [英] ignore accent in regex
本文介绍了在正则表达式中忽略重音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
Possible Duplicate:
How to ignore acute accent in a javascript regex match?
我有一些javascript:
I have some javascript as :
var myString = 'préposition_preposition';
var regex = new RegExp("epo", "ig");
alert(myString.match(regex));
有可能匹配épo和epo,如果我设置为正则表达式epo或只有épo)?
is it possible to match "épo" and "epo", if I set in regex only epo (or only épo)?
推荐答案
我最近有同样的问题。正则表达式使用ascii操作,因此不会识别特殊字符,如é
或ß
。您需要明确地将这些包含到您的正则表达式中。
I had the same problem recently. Regex operates with ascii, therefor special characters like é
or ß
are not recognized. You need to explicitely include those into your regex.
使用此:
Use this:
var regex = /[ée]po/gi;
提示:不要使用 new Regex()
它很慢,但直接声明正则表达式。这也解决了一些引用/转义问题。
Hint: Don't use new Regex()
it's rather slow, but declare the regex directly instead. This also solves some quoting/escaping issues.
这篇关于在正则表达式中忽略重音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文