Range inside a character class

We can also specify a character range inside a character class by using a hyphen ( - ) between two characters. You just have to make sure that the left-hand side character of a range is lower in the ASCII table than the right-hand side character. We can match all the digits using the regex patterns, [0123456789], or a shorter [0-9].

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.