I'm currently using ([1-9]|1[0-2])
to represent inputs from 1 to 12. (Leading zeros not allowed.)
However it seems rather hacky, and on some days it looks outright dirty.
☞ Is there a proper in-built way to do it?
☞ What are some other ways to represent number ranges?
I tend to go with forms like [2-9]|1[0-2]?
which avoids backtracking, though it makes little difference here. I've been conditioned by XML Schema to avoid such "ambiguities", even though regex can handle them fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With