.NET Regex Error: [x-y] range in reverse order

Not a bug. Inside a character class (denoted by […]) the - character must be first (some flavours allow first or last, I believe) if it is to be included as a literal. Otherwise it is expected to denote a range, such as 0-9 or A-Z or even /-..

The problem is that according to Unicode, the . comes before the /, so the range is interpreted to be backward, equivalent to specifying a range 7-4.

If you used [.-/], I would not expect a parse exception, but you wouldn’t get the results you expected.

Leave a Comment