检查字符串是否只包含utf8字母 [英] Check if string contain only utf8 letter

查看:75
本文介绍了检查字符串是否只包含utf8字母的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在寻找一种在Javascript中处理这些东西的方法。

I've been searching for a method to deal with this stuff in Javascript.

PHP有一个处理unicode字符的库,它叫做 Unicode字符属性。基于这些模式,可以通过类似 preg_match('/ ^ \p {L} + / u',$ string)的方式找到UTF-8字母。

PHP has a library that handles unicode character, which called Unicode character properties. Base on these patterns, UTF-8 letters can be found via something like preg_match('/^\p{L}+/u', $string).

我怎么能在JS中做到这一点?

How could I do this in JS?

推荐答案

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插件

这篇关于检查字符串是否只包含utf8字母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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