in reply to Using a regex to extract a version from a Un*x path

Split on "/". Process the chunks backwards: for each chunk, see if it's parsed by version.pm. If it is, this is the version, otherwise, try the next chunk. If no chunk is parseable, you cannot determine the version.

Replies are listed 'Best First'.
Re^2: Using a regex to extract a version from a Un*x path
by gcmandrake (Novice) on Mar 18, 2010 at 16:11 UTC

    I hadn't thought it through trying to split on '/'. Interesting. I'll have to see where that goes. Thanks.

    Such an amazing bunch of replies. Thanks so much, all answers are very much appreciated.

      I, too, very much like JavaFan's approach of Re: Using a regex to extract a version from a Un*x path. However, since I've already composed this reply, you might as well see it.

      To avoid the confusion introduced by the presence of  'V2' in some paths, I depend on the presence of the magical  'V2DepCheck' sub-string. (JavaFan neatly avoids this issue by parsing right-to-left, but the regex approach I use must parse left-to-right.) Many more regexes are defined than in other approaches, but I find that it sometimes pays to be painfully explicit when the problem set is ill-defined and mutable, and maintenance may be an issue.

      Code:

      Output: