Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matching arabic text with regex

Tags:

java

regex

arabic

I'm trying to match only arabic text using regex but I'm getting an exception. Here's my code:

txt.matches("\\P{Arabic}+")

Here's the exception:

Exception in thread "main" java.util.regex.PatternSyntaxException: Unknown character property name {Arabic} near index 9 \P{Arabic}+

like image 713
Jack Twain Avatar asked Jul 26 '13 17:07

Jack Twain


1 Answers

Use this character block

\p{InArabic}+

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 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)

REFERECE

like image 77
Anirudha Avatar answered Oct 24 '22 23:10

Anirudha