Cyan Cyan - 1 year ago 90
Java Question

Regular expression - between 1 to four digits, at least one non zero

I am looking for a regular expression to verify if a number between 1 to 4 digits that has at least one non zero digit.


0 -false
1 -true
000 -false
100 -true


Answer Source

You can use this look ahead based regex:


RegEx Demo

(?!0+$) is negative look ahead to assert all digits are not zeroes.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download