Regex for numerical range, show 1 and 01, but reject 0 and 00 -
i've puzzled lot, can't figure out why regex doesn't work. it's input should accept numerical range between 0 , 40. should reject 0 , 00, accept 1 or 01 , further...
where wrong?
\b([1-3]?\d{1}|40)\b
[1-3]?\d{1}
matches 0
because [1-3]
optional , \d
of course includes 0
. also, {1}
no-op - every token matched once definition.
you need this:
\b(0?[1-9]|[1-3]\d|40)\b
Comments
Post a Comment