Examples of character range

The following is a regex that matches any uppercase or lowercase alphabet in the English language:

    [a-zA-Z] 

The a-z pattern is for the lowercase character range and A-Z is for the uppercase character range.

The following regex matches any alphanumeric characters:

    [a-zA-Z0-9] 

Alpha numeric characters consist of any English alphabets and digits.

The following regex matches any hexadecimal character:

    [a-fA-F0-9] 

We know that hexadecimal characters consist of digits, 0 to 9, and letters, A to F (ignore casing). The preceding regex pattern shows a character class that includes these two character ranges. We use a-f and A-F ranges to make it match uppercase or lowercase letters.

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.