用正则表达式匹配阿拉伯语文本 [英] Matching arabic text with regex
本文介绍了用正则表达式匹配阿拉伯语文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用正则表达式仅匹配阿拉伯语文本,但出现异常.这是我的代码:
I'm trying to match only arabic text using regex but I'm getting an exception. Here's my code:
txt.matches("\\P{Arabic}+")
例外:
线程主"中的异常java.util.regex.PatternSyntaxException:索引9附近的未知字符属性名称{Arabic} \ P {阿拉伯语} +
Exception in thread "main" java.util.regex.PatternSyntaxException: Unknown character property name {Arabic} near index 9 \P{Arabic}+
推荐答案
使用此字符块
\p{InArabic}+
在Java Unicode脚本中,块,类别和二进制属性是用\p
和\P
(负效果)编写的
In java Unicode scripts, blocks, categories and binary properties are written with the \p
and \P
(negated effect)
- Scripts are specified either with the prefix
Is
or by using thescript
keyword(supported scripts) - Blocks are specified with the prefix
In
or by using the keywordblock
(supported blocks) - Categories may be specified with the optional prefix
Is
or using keywordgeneral_category
orgc
(supported categories) - Binary properties are specified with the prefix
Is
(supported properties)
这篇关于用正则表达式匹配阿拉伯语文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文