How can I modify this regex to require a specific numeric range and also allow an empty string? -
How can I modify this regex to require a specific numeric range and also allow an empty string? -
i have next regex:
^([1-9]){3,5}[1-8]$
it works restrict strings within range, need alter it'll allow empty string. how can this?
^(([1-9]){3,5}[1-8])?$
use (?:
if care captured groups, if don't, can remove brackets around [1-9]
. brackets around whole sequence must kept, though, ?
quantifier still applies correctly (preceding grouping 0 or 1 times). shorter (maybe more correct) version be:
^(?:\d{3,5}[1-8])?$
this homecoming 1 match, input string whole.
regex
Comments
Post a Comment