Regex for multiple of 1000 accepting values ​​greater than 25000 and decimal invalid

I have two combinations:

  • To check multiple 1000 which ^[1-9]+[0-9]*000$.

  • To check the value is greater than 25000, which ^\\d{6,}$|^[3-9]\\d{4}$|^2[5-9]\\d{3}$.

When I tried to combine two regular expressions with a positive lookahead operator, as shown below,

^(?=[1-9]+[0-9]*000)(?=\\d{6,}$|^[3-9]\\d{4}$|^2[5-9]\\d{3})*$

Its accepting values, such as 25000100.35000100, which are not a multiple of 1000.

Is it possible to execute both scripts with a single regex?

+4
source share
4 answers
^(2[5-9]\d*|[3-9]\d+|[12]\d{2,})000$

Look in action

The idea is this:

  • 2[5-9]\d* - 25-29 with optional digits after that> = 25
  • [3-9]\d+ - 3-9 with one or more digits after that> 25
  • [12]\d{2,} - 1 2 > 25
  • 000 - 1000
+2

^([1-9]\d{2,}|[3-9]\d|2[5-9])000$

https://regex101.com/r/vJ8xU6/3

+2

, , 000, 1000, , X000, X.

  • X → = 3 ( [1-9]\d\d\d*), X000 >= 100000 > 25000
  • X - 2 , X a > 2 ( [3-9]\d), X000 >= 30000 > 25000
  • X - 2 , X 2, X a >= 5 ( 2[5-9]), X000 >= 25000 = 25000.

X ( , ), ([1-9]\d\d\d*|[3-9]\d|2[5-9]) .

([1-9]\d\d\d*|[3-9]\d|2[5-9])000

. : https://regex101.com/r/bV1kN3/1

+2

.
1 0, .

25 1000, (?:2[5-9]|[3-9]\d|[1-9]\d{2}|1000).

.

 (?:
      2 [5-9] 
   |  [3-9] \d 
   |  [1-9] \d{2} 
   |  1000
 )

1000, \d's.
. , 000, ..

 (?:
      2 [5-9] 
   |  [3-9] \d 
   |  [1-9] \d{2,} 
 )
 000
0

Source: https://habr.com/ru/post/1625551/


All Articles