Why is the regex to match numbers from 1 to 10 commonly written as follows?
[1-9]|10
Instead of:
[1-10]
Or this:
[1-(10)]
Sometime a good drawing worth 1000 words...
Here are the three propositions in your question and the way a regex flavour would understand them:
Invalid regexp !!
This regex is invalid because a range is opened (1-
) with a digit but not closed with another digit (ends with (
).
A range is usually bound with digits on both sides or letters on both sides.
Images generated with Debuggex