O'Reilly logo

Java 9 Regular Expressions by Anubhava Srivastava

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

The intersection of character classes

The intersection operation on character classes results in a composite class that contains every character allowed by all of its operand (inner) classes or, in other words, matches characters that belong to all the character classes in the composite character class pattern. The intersection operator is as follows:

&& 

For example, consider the following composite character class using the && operator:

 [A-Z&&[PQR]] 

This matches any character that is in the range of A to Z and is one of the single P, Q, or R characters. However, the preceding regular expression can also be simply written as follows:

[PQR] 

The following composite character class using intersection matches the digits, 5 and 6, since ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required