I am working on a valid regex for valid integer numbers like the following:
- 999
However, it should not be allowed to match empty string. The closest I can find is:
(0) | \\ d {1,3}
Who says to me that a match string will be either a zero or a series of digits between 1 or 3 characters, however, the still string is still Matches this method. What is the proper way to exclude the empty string from this reggae?
This (only) one to three numerical digits (including 0 or 00 or 01 or 012) Is not that if the latter are):
^ \ d {1,3} $
this will not match empty string (but then your Original compressed expression will not be).
(To allow this as part of a larger string, an ^
and $
).
But maybe again RegX is not the best option - the number which is the original language you are using is not a numerical function? 0 to allow 0 but no other 0-prefix numbers, you can use it:
0 | [1- 9] \ d {0, 2}
Or, to ensure that the whole match is:
^ (?: 0 | [1- 9] \ d {0,2}) $
Comments
Post a Comment