6

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}+

Adil
  • 4,503
  • 10
  • 46
  • 63
Jack Twain
  • 6,273
  • 15
  • 67
  • 107

1 Answers1

15

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

Anirudha
  • 32,393
  • 7
  • 68
  • 89