Note: This question is not about available libraries which parse version strings or about how to write regex pattern in general. I have to feed a pattern into an API call so using another library is not an option for me.
I need to match a version string like e.g. "9.3"
or "12.5"
against a minimum version number "11.2"
. I.e. "9.9"
or "9.10"
must not match while "11.2"
, "11.10"
or "20.0"
should.
In Python re
is there a reasonable way to accomplish this? Using approaches like this one lead to an expression like this one:
r"^(([2-9]\d|1[2-9])\.\d{1,}|11\.([2-9]|\d{2,}))(\.\d+)*$"
which is hard core to read and zero flexible.
In 2020 isn't there an easier or more generic way to deal with decimal numbers (not digits) in regular expressions in Python?
Maybe expression generators which take a more abstract description and generate expressions?