I'm extracting a four-part version number from a filename and converting it to a SemVer-compliant version.
- Filename:
MyApp v2020.8.3.1.exe
- SemVer:
2020.8.3-r1
I've been successful at doing this using two steps:
sVersion = Regex.Match("MyApp v2020.8.3.1.exe", "[A-Za-z ]|\.[A-Za-z]").Value
oSemver = New Regex("\.(?=[^\.]+$)")
sSemVer = oSemver.Replace(sVersion, "-r")
This produces the desired SemVer-compliant version.
However, for the sake of brevity, I'd like to combine these two steps into a single operation.
I tried several variations on a couple of Q&As I found:
...but I didn't have much luck.
For example:
([A-Za-z ]|\.[A-Za-z])|(\.(?=[^\.]+$))
replaced with $2
produces only the four-part version number 2020.8.3.1
.
Is this possible, given the constraints I'm working with?
--EDIT--
I only need a SemVer-compliant version number, not a new filename. In other words, I need to strip off all the extraneous characters (in this case MyApp v
and .exe
) and replace the final .
in the four-part version number with -r
.