用正则表达式匹配阿拉伯文本 [英] Matching arabic text with regex

查看:39
本文介绍了用正则表达式匹配阿拉伯文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用正则表达式仅匹配阿拉伯文本,但出现异常.这是我的代码:

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(否定效果)

  • Scripts are specified either with the prefix Is or by using the script keyword(supported scripts)
  • Blocks are specified with the prefix In or by using the keyword block(supported blocks)
  • Categories may be specified with the optional prefix Is or using keyword general_category or gc(supported categories)
  • Binary properties are specified with the prefix Is (supported properties)

参考

这篇关于用正则表达式匹配阿拉伯文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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