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

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -