I have the task of refactoring some code which determines if a process step is to be re-run or not. The check I am concerned with is comparing whether a script or package is of a newer or later version than the one that the step was previously built with. So, I need to extract a version string from a UN*X path. Of course, there are multiple version types and a new change in the configuration management system complicates things. Incompatible types cause a step to be re-run (and do pick up, hopefully, the new version path.
Here are some examples of the paths that I will need to deal with:
'/tool/a/r/V2/V2DepCheck/1.109.2.1/V2DepCheck.pm' '/tool/a/r/p4/r/main/V2/V2DepCheck/169441/V2DepCheck.pm' '/tool/a/r/p4/r/branches/bd32b/V2/V2DepCheck/175507/V2DepCheck.pm' '/home/me/cvs/V2/V2DepCheck.pm' '/tool/a/r/boost/1.36.0' '/tool/a/r/cadence/itk/itkvd/v007'
The object is to extract the versions as strings, respectively:
1.109.2.1 169441 175507 undef 1.36.0 007
I've come up with a regex which works, but is hardly elegant. To extract a version, I use the following:
$path =~ m#/tool/a/r/(?:p4/r/main/|p4/r/branches/.+/)?.*/\D?([0-9.]+)\ +b#
Which works at least with the samples that I've fed it. If anyone has any suggestions for this poor soul, it would be most appreciated.
Your humble servant,
gcmandrake
physicist
In reply to Using a regex to extract a version from a Un*x path by gcmandrake
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |