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

First, you need an accurate definition from the UNIX documentation. If you look at only 5 examples and extrapolate, you might make a bad assumption. You probably do not need the regex to match the whole path. I'm seeing numeric values \d+, after a \/, that begins with an optional v?. No other item in the path conforms to to these rules, so you don't have to worry about anything else. Try:

if($path =~ /\/(v?\d+)/) { $version = $1 } else { $version = undef }

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

    A specification is an evil word around here (as is a plan). My main problem is that there is a constant churn in the types of versions. Users can (and do) create their own types of versions. I thought that I had it captured with the regex described earlier, but now I'm leaning back toward factory methods. So it goes. Thanks for the suggestion.