Using character range in a character classe [a-z]


What is a character range in a character class? How to specify a character range in a character class in a regular expression?

I have a string of hexadecimal digits, 46594963656E7465722E636F6D and want to use character ranges in a character class to validate it.



A character range defines a set of possible characters of an ASCII code range using '-' between the first and the last character of the range in a character class.

Here are some examples of character ranges:

[0-9]        # same as [0123456789]
[A-F]        # same as [ABCDEF]

If '-' is the first or last character in a character class, it is treated as an ordinary character.

The regular expression to a match a string of hexadecimal digits is:


[ - begin of a character class
0-9 - character range from 0 to 9
a-f - character range from a to f
A-F - character range from A to F
] - end of a character class

Click the button to test this regular expression here online:

2013-01-22, 2149👍, 0💬