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 |