Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular expression to match a non-zero, zero-padded integer

Tags:

regex

I need help with a pattern to match a zero-padded integer which is not all zeros. It can have zero to n leading zeros. So far I have:

^[0-9]{0,}[1-9]{1}$"

but this does not get things like 000860 because of the last zero. I feel like this should be simple, but I can't get it. Any help would be much appreciated.

EDIT: A few people have asked which engine/language this is. I thought regex was standardized so it wouldn't matter. But it's .NET.

like image 614
rory.ap Avatar asked Sep 02 '14 20:09

rory.ap


1 Answers

Why not using this:

^0*[1-9][0-9]*$

? Btw, you missed to specify the regex engine in use. But the above pattern should work in almost any regex engine.

like image 177
hek2mgl Avatar answered Nov 15 '22 04:11

hek2mgl