Regex to match 0 - 999 but not blank
Posted
by James Cadd
on Stack Overflow
See other posts from Stack Overflow
or by James Cadd
Published on 2010-06-18T15:53:49Z
Indexed on
2010/06/18
16:03 UTC
Read the original article
Hit count: 412
regex
I'm working on a regex to match valid integer numbers such as the following:
- 0
- 1
- 99
- 999
However it should not allow matching an empty string. The closest I can get is:
(0)|\\d{1,3}
Which to me says a matching string will have either a zero or a series of digits between 1 and 3 characters long. However, empty strings still appear to match this pattern. What's the proper way to exclude empty strings from this regex?
© Stack Overflow or respective owner