I'm trying to find a regular expression for a float with a fixed maximum (for example 4) number of significant figures.
this should match with:
- 123.4
- 12.34
- 1.2
- 223
- 0.1234
- 0.000001234
the problem is that the number of non-zeros before and after the dot has to be at most 4 in total.
I tried to split the problem and found solutions for the cases:
- 0.xxxx
- 0.000xxx
- xxxx
But I didn't find a solution for the case that significant digits are found before and after the dot. (examples: 1.23 2.345
)
update: I think I found a solution:
^(?!(?:.*[1-9](\.?[0-9]){4,}))([-+]?\d+\.?\d*?)$