I have two combinations:
For checking multiple of 1000 which is ^[1-9]+[0-9]*000$
.
For checking value greater than 25000 which is ^\\d{6,}$|^[3-9]\\d{4}$|^2[5-9]\\d{3}$
.
When I tried to combine two regex with positive lookahead operator like below,
^(?=[1-9]+[0-9]*000)(?=\\d{6,}$|^[3-9]\\d{4}$|^2[5-9]\\d{3})*$
Its taking values such as 25000100,35000100,which is not a multiple of 1000.
Is it possible to achieve both scenarios through one regex?
This should work
^([1-9]\d{2,}|[3-9]\d|2[5-9])000$
https://regex101.com/r/vJ8xU6/3
^(2[5-9]\d*|[3-9]\d+|[12]\d{2,})000$
See it in action
The idea is:
2[5-9]\d*
- 25-29 with optional digits after that is >= 25[3-9]\d+
- 3-9 with one or more digits after that is > 25[12]\d{2,}
- 1 or 2 with two or more digits after that is > 25000
- add three zeroes at the end for 1000 divisibilityObviously any string ending in 000 is a multiple of 1000, so given a string X000, let's just worry about the X.
[1-9]\d\d\d*
), then X000 >= 100000 > 25000[3-9]\d
), then X000 >= 30000 > 250002[5-9]
) then X000 >= 25000 = 25000.Any other possible X is going to result in a smaller number (or something that isn't a number), so just throw those together into a group ([1-9]\d\d\d*|[3-9]\d|2[5-9])
for the prefix.
([1-9]\d\d\d*|[3-9]\d|2[5-9])000
See Also: https://regex101.com/r/bV1kN3/1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With