用正则表达式匹配阿拉伯文本 [英] 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}+")
这是一个例外:
线程main"中的异常 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
(否定效果)
- 脚本 使用前缀
Is
或使用script
关键字(支持的脚本) - 块使用前缀
In
或使用关键字block
(支持的块) - Categories 可以使用可选前缀
Is
或使用关键字general_category
或gc
(支持的类别) - 二进制属性 使用前缀
Is
指定(支持的属性)
- 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屋!
查看全文