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 of these character classes; we just simply write them inside each other.
For example, consider the following composite character class:
[A-D[PQR]]
This matches any character in the range of A
to D
or any single character P
, Q
, or R
. This regular expression can...