某些语言使用不同的文字,如英语和西班牙语使用拉丁文,而阿拉伯语和俄语用阿拉伯文和俄文。Script 和 Script_Extensions Unicode 属性允许正则表达式根据字符所属的文字或该文字所属的文字扩充进行匹配。
比如,A 属于 拉丁文,ε 属于希腊 (Greek)文。
jslet mixedCharacters = "aεЛ";// Using the canonical "long" name of the scriptmixedCharacters.match(/p{Script=Latin}/u); // a// Using a short alias for the scriptmixedCharacters.match(/p{Script=Grek}/u); // ε// Using the short name Sc for the Script propertymixedCharacters.match(/p{Sc=Cyrillic}/u); // Л详见 the Unicode specification 和 Scripts table in the ECMAScript specification.
某字符用于多种文字时,Script 优先匹配最主要使用那个字符的文字。如果想要根据非主要的文字进行匹配,蜜桃成人网站入口可以使用 Script_Extensions 属性 (简写为Scx).
js// ٢ 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]