Home > OS >  Regex - greater than specific release version
Regex - greater than specific release version

Time:04-14

I need to make Regex expression which will take into account only versions greater than release version release/2022.2.1 So that version should be excluded, along with all previous (2022.1.1, 2021.4.1 etc.) The first version that I would like to include will be release/2022.2.2 and any after that. So I made a regex:

^release/2022.[2-9].[2-9]|release/2023.[\d].[\d]

And this works! But this will mean that for every year I need to add | and after that years that are coming (2024, 2025... etc.)

Obviously this is not an optimal way. How to optimize this?

Thanks!!!

CodePudding user response:

If you need a regex for all upcoming versions in this format until 2099, take

^release\/20(22\.(2\.[2-9]|[3-9]\.\d)|(2[3-9]|[3-9]\d)\.[\d]\.[\d])
  • ^release\/20 - fix part
  • 22\.(2\.[2-9]|[3-9]\.\d) - all values from 22.2.3 to 22.9.9
  • (2\.[3-9]|[3-9]\d) - years 23-29 or 30-99
  • year 23-99 \.[\d]\.[\d] - all versions, .0.0 to .9.9

You can see a more detailed explanation of what's what here

I still recommend against using regex and use any other language

  • Related