使用JavaScript正则表达式匹配Unicode“名称”

3
在JavaScript中,我们可以使用Unicode转义序列匹配单个Unicode码点或码点范围,例如:
"A".match(/\u0041/) // => ["A"]
"B".match(/[\u0041-\u007A]/) // => ["B"]

但是我们如何使用JavaScript正则表达式创建一个匹配包含任何Unicode“字母”的适当名称的表达式?是否有一系列字母?JavaScript中的特殊正则表达式序列或字符类?

假设我的网站必须验证可能在拉丁语为基础的语言以及希伯来语,西里尔语,日语(片假名,平假名等)中的名称,这在JavaScript中可行吗?还是唯一明智的选择是委托给具有更好的Unicode支持的后端语言?


你可能还想阅读https://dev59.com/IFLTa4cB1Zd3GeqPZU83#4324957和http://stackoverflow.com/questions/4718266/advice-on-how-to-validate-names-and-surnames-using-regex/4719582#4719582。 - ninjalj
请访问以下链接:http://www.kalzumeus.com/2010/06/17/falsehoods-programmers-believe-about-names/ 和 http://blog.jgc.org/2010/06/your-last-name-contains-invalid.html - ninjalj
我真的认为你应该仔细考虑你最后的选择:将后端工作委托给实际支持Unicode标准的语言。 - tchrist
2个回答

5

0

我使用这个网站http://www.fileformat.info来定义符号的Unicode。

Unicode块(基本拉丁文、.+、西里尔文、.+、阿拉伯文和其他): http://www.fileformat.info/info/unicode/block/index.htm

Unicode字符类别(在JS中不起作用): http://www.fileformat.info/info/unicode/category/index.htm

字母(A-я): http://www.fileformat.info/info/unicode/char/a.htm

字体(每种字体支持哪些字符): http://www.fileformat.info/info/unicode/font/index.htm

所有内容的索引 http://www.fileformat.info/info/unicode/index.htm


4
你不能使用Unicode块作为代理来表示Unicode脚本,因为你真正想要的是后者。Unicode标准明确提到了这一点。 - tchrist

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接