I need to obtain from a string version (of maximum 3 chars like sql varchar(3), the “next version” with the following simple rule:
if its last chars constitutes a number, increment it, if it always fits max 3 chars, else, leave it as is.
Say “Hi1” => “Hi2”, “H9” => “H10” but “xx9” will remain unchanged.
Public Shared Function GetNextVersion(oldVersion As String) As String
Dim newVersion As String = String.Empty
If Regex.IsMatch(oldVersion, "?????") Then
Return newVersion
Else
Return oldVersion
End If
End Function
This will be your regex, it will match anything with a gruop of letters followed by a group of numbers.
It will contain two named capture groups, “prefix” which is the initial characters, and “version” which has your version.
Cast the version to an int, increment it, and return the new version number by concatenating the prefix and new version.
So, you’ll end up with something like this