匹配Unicode“名称”使用JavaScript正则表达式 [英] Matching a Unicode "name" with a JavaScript Regular Expression

查看:221
本文介绍了匹配Unicode“名称”使用JavaScript正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在JavaScript中,我们可以使用Unicode转义序列匹配单个Unicode代码点或代码点范围,例如:

In JavaScript we can match individual Unicode codepoints or codepoint ranges by using the Unicode escape sequences, e.g.:

"A".match(/\u0041/) // => ["A"]
"B".match(/[\u0041-\u007A]/) // => ["B"]

但我们如何创建正则表达式以匹配必须包含的正确名称使用JavaScript正则表达式的任何Unicode字母?有一系列字母吗? JavaScript中的特殊正则表达式序列或字符类?

But how could we create a regular expression to match a proper name which must include any Unicode "letter" using a JavaScript regular expression? Is there a range of letters? A special regex sequence or character class in JavaScript?

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

Say my website must validate names that could be in latin based languages as well as Hebrew, Cyrillic, Japanese (Katakana, Hiragana, etc.) is this feasible in JavaScript or is the only sane choice to delegate to a backend language with better Unicode support?

推荐答案

这是一个JS插件,它为RegEx添加了Unicode支持

Here's a JS plugin that adds Unicode support to RegEx

http: //xregexp.com/plugins/

这篇关于匹配Unicode“名称”使用JavaScript正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆