Why should you use composite character classes?

We should use composite character classes for the following reasons:

  • To create new custom character classes from predefined Unicode blocks. For example, to match all the letters in an Arabic Unicode block, we can use the following:
  • To avoid potentially slower lookahead or lookbehind patterns by using the intersection or subtraction operation on multiple character classes.
  • To enhance the readability of the regular expression.

Get Java 9 Regular Expressions now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.