Home > other >  How to match version name later than 1.1.7? (or any version that I want)
How to match version name later than 1.1.7? (or any version that I want)

Time:11-02

I'm using Firebase Remote Config and with my current setup, the only way to make the config only released to user with correct version is by using regex.

I'm looking for a regex that match any version released later than A.B.C

So if new version is x.y.z then the following must be true for it to match:

(x > A) or {(x = A) and [(y > B) or ((y = B) and (z > C))]}

Real number example:

Match any version equal to or later than 1.1.7:

Match:

1.1.7
1.1.8
1.1.69
1.2.0
1.10.0
2.0.0

Don't match:

1.1.6
1.0.34
0.5.0
0.77.0

I have tried this regex: ^(([2-9]|[0-9]{2,}).*|1\.(([0-9]{2,}).*|[1-9]\.([0-9]{3,}|[0-9]{2,}|[7-9]))) but it doesn't match 1.2.0

CodePudding user response:

You can try this regex:

^([2-9]|1\d|1\.([2-9]|1\d|1\.([7-9]|\d\d)))

Demo here

CodePudding user response:

You could use

^(?:1\.(?:1\.(?:[789]|[1-9]\d )|(?:[1-9]\d |[2-9])\.\d )|(?:[1-9]\d |[2-9])\.\d \.\d )$

Regex demo

The pattern matches:

  • ^ Start of string
  • (?: Non capture group
    • 1\. Match 1.
    • (?: Non capture group
      • 1\. Match 1.
      • (?:[789]|[1-9]\d ) Match either 7 8 9 or 10
      • | Or
      • (?:[1-9]\d |[2-9]) 10 or 2-9
      • \.\d Match . and 1 digits 0-9
    • ) Close non capture group
    • | Or
    • (?: Non capture group
      • [1-9]\d 10
      • | Or
      • [2-9] Match 2-9
    • ) Close non capture grouop
    • \.\d \.\d Match . 1 digits . 1 digits
  • ) Close outer non capture group
  • $ End of string
  • Related