0

/^[A-Z][A-Za-z.'\- ]+$/我有这个用于检查名称的正则表达式。

因此,当我输入 George 或 George Harris 或 George-Harris 时,就可以了。问题是它与我的语言(希腊语)中的名称和单词不匹配

如何向此正则表达式添加 unicode 支持?

4

2 回答 2

1

XRegExp库添加了对字符类的支持以及JS 正则表达式实现中缺少的其他内容。我想你会发现它的Unicode 插件特别有用。

于 2012-06-26T17:02:41.350 回答
0

You can use unicode to match greek letters. Here's a map of the greek characters in unicode. /[A-Z]/i would translate /[\u03B1-\u03C9]/i if I understand right. So for greek characters (and, in my country, diacritics), you need to know their unicode equivalent and use them as \uxxxx in regular expressions.

In my experience, if the javascript file is saved as utf-8 and the webpage that uses it is utf-8, you can use such characters directly. So something like /α/.test('α200β') works in such a setup.

于 2012-06-26T17:01:16.193 回答