regex - Regular expression that doesn't accept single 0 but does accept 10 -
i have regular expression:
^[ 0-9a-z] [ 0-9]{4}[0-9][/ ][ 0-9a-z]$
and works fine, have exclude 0 in construct [ 0-9]{4}[0-9]
in way.
the string a 0/a
should not match
the string a 10/a
should match
so have check if first occurrence of number in second group 0
or not.
how can that? if or not clear, so.
so have check if first occurrence of number in second group 0 or not.
i think need negative lookahead:
^[ 0-9a-z] (?! *0)[ 0-9]{4}[0-9][/ ][ 0-9a-za-z]$ ^^^^^^^
see regex demo.
since [ 0-9]{4}[0-9]
matches 4 digits or spaces (there may 4 spaces) , [0-9]
matches digit obligatorily, (?! *0)
make sure pattern above not match spaces followed 0
.
Comments
Post a Comment