-1

Hello i have regex like this

^[\d]{4,5}([;]\d{4,5})*$|(^[\d]{4,4}([:]\d{4,5})$)|^[\d]{4,5}(\s[;]\s\d{4,5})*$|(^[\d]{4,4}(\s[:]\s\d{4,5})$)

I need effect like this:

  • 12345 : 12345 - allowed

  • 12345 : 1234 - not allowed

  • 12345 : 12344 - not allowed

  • 1234 : 1235 - allowed

  • 1234 : 12345 - allowed

Generally - left <= right

Rest can be stay

Someone know how to resolve this problem?

RetupK
  • 53
  • 7
  • Though people do [weird things](https://stackoverflow.com/q/8647893/1169519) with RegExps, it's better to do maths where math is needed. – Teemu Apr 09 '21 at 11:52

1 Answers1

0

The problem you describe cannot be described by a regular language, as such I doubt this can be solved with a regex. You could however solve this easily in JS:

 const [a, b] = str.split(":");
 if(+a <= +b) /*...*/
Jonas Wilms
  • 132,000
  • 20
  • 149
  • 151