How do character ranges ACTUALLY work in regex? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

How do character ranges ACTUALLY work in regex?

To avoid confusion, I'm not asking how to use character ranges in regex. I'm asking how they actually work behind the scenes. Character ranges in regex are indicated using the - (dash) character between square brackets. At first, I thought we can only range between A-Z (lowercase or uppercase) and 0-9. Just now, I found out you can also do N-P. I thought to myself what if it actually uses ASCII character codes like if I defined [ -/], it'll be the same as 32 <= x <= 47 (32 and 47 are ASCII codes for space ' ' and forward slash '/'). Do character ranges work like this???

12th May 2019, 6:28 AM
luʁi
2 Answers
+ 4
No, it's not based on ascii order, it's based on alphabetical order.
12th May 2019, 6:57 AM
Calviղ
Calviղ - avatar
12th May 2019, 7:15 AM
Микола Федосєєв
Микола Федосєєв - avatar