且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

检查字符串是否只包含utf8字母

更新时间:2023-02-26 13:09:46

JavaScript唯一的unicode功能是它允许你匹配一个字符与 \\\DDDDD ,所以如果你需要 \P {L} ,没有运气。

JavaScript's only unicode feature is that it lets you match one characters with \uDDDD, so if you need \P{L}, no luck.

然而,出色的正则表达式食谱(与正则表达式大师Jan Goyvaert一起)的共同作者Steven Levithan有一个备用库称为 XRegExp ,它具有更多功能,包括您寻求的功能。您可以在RegexBuddy(Jan的独立应用程序)和 RegexPal 中进行测试。

However, Steven Levithan, co-author of the excellent Regular Expressions Cookbook (together with regex guru Jan Goyvaert), has an alternate library called XRegExp that has many more features, including those you seek. You can test it both in RegexBuddy (a standalone app by Jan) and in RegexPal.

从文档中引用:


XRegExp支持匹配Unicode类别,脚本,块和
其他属性通过插件脚本。使用
\p {...},\P {...}和\p {^ ...}匹配此类令牌。

XRegExp supports matching Unicode categories, scripts, blocks, and other properties via addon scripts. Such tokens are matched using \p{…}, \P{…}, and \p{^…}.

请参阅 XRegExp Unicode插件