The union of character classes

The union of character classes will match a character that would be matched by any of the composing character classes. Essentially, this is the definition of the union operation in general. In regular expressions, it is possible to create unions of character classes by simply writing a character class inside another.

You may remember that character classes open with the [ character and close with the ] character, and we can list characters and character ranges between the opening and closing brackets.

In addition to those, we can use other character sets inside the brackets, and the resulting set will be the union of all these character classes. This way, there is no union operator to create the composition ...

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

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.