用正则表达式匹配阿拉伯文本

编程入门 行业动态 更新时间:2024-10-27 13:25:35
本文介绍了用正则表达式匹配阿拉伯文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

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

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_categorygc(支持的类别)二进制属性 使用前缀Is 指定(支持的属性) 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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-17 04:41:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/904383.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:阿拉伯   文本   正则表达式

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!