Oh, great & powerful Perl monks, please allow this unworthy physicist to ask this question:

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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.