I have this expression
I think you are looking for
See the regex demo
^- start of string
(?!0*[.,]?0+$)- a negative lookahead that will fail the match if the whole string is equal to 0+ zeros followed with 1 or 0 commas or dots and followed with one or more zeros (if the value is
\d*- zero or more digits
[.,]?- an optional comma or dot
\d+- 1 or more digits
$- end of string.
Remember that you do not need
$ when using the pattern with the
String#matches method, but it is a good idea to keep them explicit in the pattern for better readability and further testing.