Regular expression to match non-zero zero padding
I need help with a pattern to match zero padding to an integer that doesn't match all zeros. It can have zero to n leading zeros. So far I have:
^[0-9]{0,}[1-9]{1}$"
but because of the last zero it doesn't get things like 000860
. I feel like it should be easy, but I can't get it. Any help would be much appreciated.
EDIT: Several people have asked which engine / language this is. I thought the regex was standardized so it doesn't matter. But this is .NET.
source to share
Well here's my trick:
0+[1-9]+[0-9]{0,}
it captures at least one zero (add ?
after the first one 0
instead +
if it is possible to have no leading zeros), at least one non-zero number, then any number of zeros and other digits.
and if you want to write a number without zeros:
0+([1-9]+[0-9]{0,})
which just puts the part after the leading zeros into the capture group.
all this successfully analyzes:
000860 000860123 000800 000810 0008
source to share