Unicode property escapes

您所在的位置:网站首页 zh男明星缩写 Unicode property escapes

Unicode property escapes

2023-05-13 00:22| 来源: 网络整理| 查看: 265

某些语言使用不同的文字,如英语和西班牙语使用拉丁文,而阿拉伯语和俄语用阿拉伯文和俄文。Script 和 Script_Extensions Unicode 属性允许正则表达式根据字符所属的文字或该文字所属的文字扩充进行匹配。

比如,A 属于 拉丁文,ε 属于希腊 (Greek)文。

let mixedCharacters = "aεЛ"; // Using the canonical "long" name of the script mixedCharacters.match(/\p{Script=Latin}/u); // a // Using a short alias for the script mixedCharacters.match(/\p{Script=Grek}/u); // ε // Using the short name Sc for the Script property mixedCharacters.match(/\p{Sc=Cyrillic}/u); // Л

详见 the Unicode specification 和 Scripts table in the ECMAScript specification.

某字符用于多种文字时,Script 优先匹配最主要使用那个字符的文字。如果想要根据非主要的文字进行匹配,我们可以使用 Script_Extensions 属性 (简写为Scx).

// ٢ is the digit 2 in Arabic-Indic notation // while it is predominantly written within the Arabic script // it can also be written in the Thaana script "٢".match(/\p{Script=Thaana}/u); // null as Thaana is not the predominant script super() "٢".match(/\p{Script_Extensions=Thaana}/u); // ["٢", index: 0, input: "٢", groups: undefined]


【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3