Wolfram Research

Function Repository Resource:

SelectVersionNumber

Source Notebook

Choose a version number matching a specification

Contributed by: Bob Sandheinrich

ResourceFunction["SelectVersionNumber"][versions,spec]

selects the highest version number from versions that satisfies the specification spec.

Details and Options

The specification can use operators including GreaterThan, LessThan, GreaterEqualThan, LessEqualThan and EqualTo containing version numbers. Operators can be combined using And.
Alternatively, the specification can be given as a string.
When spec is a string, it supports specifications from Cargo including a wildcard character "*" for pattern matching and the comparison prefixes "<", "<=", ">", ">=", "="; as well as the following forms:
"^x.y.z" any higher version starting with "x"
"~x.y.z"|"~x.y" any higher version starting with "x.y"
"~x" any higher version starting with "x"
In string specifications, commas represent And logic.

Examples

Basic Examples

Select the largest version less than a specified value:

In[1]:=
ResourceFunction["SelectVersionNumber"][{"1.0.0", "2.2.2", "1.2.3"}, LessThan["1.6.3"]]
Out[1]=

Scope

Look for a specific value:

In[2]:=
ResourceFunction[
 "SelectVersionNumber"][{"1.0.0", "2.2.2", "1.2.3"}, "1.0.0"]
Out[2]=

Use caret notation:

In[3]:=
ResourceFunction[
 "SelectVersionNumber"][{"1.0.0", "2.2.2", "1.2.3"}, "^1.1.0"]
Out[3]=

Use tilde notation:

In[4]:=
ResourceFunction[
 "SelectVersionNumber"][{"1.0.0", "1.1.5", "2.2.2", "1.2.3"}, "~1.1.1"]
Out[4]=

Use a wildcard:

In[5]:=
ResourceFunction[
 "SelectVersionNumber"][{"1.0.0", "1.3.5", "2.2.2", "1.1.3"}, "2.*"]
Out[5]=

Combine multiple restrictions using And:

In[6]:=
ResourceFunction["SelectVersionNumber"][{"1.0.0", "2.2.2", "1.2.3"}, GreaterThan["1.1.3"] && LessThan["2.0.0"]]
Out[6]=
In[7]:=
ResourceFunction["SelectVersionNumber"][{"1.0.0", "2.2.2", "1.1.3"}, "~1.1.1" && LessEqualThan["2.2.3"]]
Out[7]=

Combine multiple string notations with commas:

In[8]:=
ResourceFunction[
 "SelectVersionNumber"][{"1.0.0", "1.3.5", "2.2.2", "1.1.3"}, "< 2.0,= 1.3.5, ^1.3.0, 1.*,~1.3"]
Out[8]=

Properties and Relations

When no versions match the specification, a Missing result is given:

In[9]:=
ResourceFunction[
 "SelectVersionNumber"][{"1.0.0", "1.3.5", "2.2.2", "1.1.3"}, "~0.3.6"]
Out[9]=

Using equal notation is the same as giving the version directly:

In[10]:=
ResourceFunction[
 "SelectVersionNumber"][{"1.0.0", "1.3.5", "2.2.2", "1.1.3"}, "= 1.3.5"]
Out[10]=
In[11]:=
ResourceFunction[
 "SelectVersionNumber"][{"1.0.0", "1.3.5", "2.2.2", "1.1.3"}, "1.3.5"]
Out[11]=

Resource History

Related Resources

License Information