Could anyone please advice best optimal regular expression to extract Version number from file names. Files of any type like JAR or any other type.
As individual teams are using there own ways to have version number like some added at start, some at end, some at middle, some with more info with version number etc. etc.
So, looking for a best optimal regular expression to get version number from file names.
As per my findings, below regular expression is the optimal solution: -
To get version name from filename (filename without extension), if the version number is anywhere in file name except at starting: -
([_-]\d+(?:[.\-_]\w*\d+)+)
Below are few filenames having different-different varieties of version number and using above Regular Expression, able to extract version number successfully.: -
Snap is captured from https://regex101.com/
And if the version number is at start of filename then same regex as above only
^(\d+(?:[.\-_]\w*\d+)+)