in reply to Regex creation
Handwaving vague idea, but . . . . First thing come up with a regex for what you consider a "version number"; e.g. qr{^( \d+ (?:\.\d+)? \w+* )$}x or whatever.
Update: Fish!
#!/usr/bin/env perl use 5.018; my $version_number_re = qr{^( \d+ (?:\. \d+)* (?:\w+)? )$}x; my $target_component_re = qr{([^/]+?)}x; my $rest_re = qr{.*}; while( <DATA> ) { chomp; my @path_components = split( qr{/}, $_ ); my $version_idx; FIND_VERSION: for my $idx ( 0 .. $#path_components ) { if( $path_components[ $idx ] =~ $version_number_re ) { $version_idx = $idx; last FIND_VERSION; } } if( $version_idx ) { my $candidate_re = join( q{/}, ( $version_idx-2 >= 0 ? @path_components[0..$version_idx-2 +] : (q{NO ROOM}) ), ($target_component_re) x 2, ($version_idx < $#path_components ? $rest_re : ()) ); my( $group, $version ) = m{$candidate_re}; say qq{Original:\n$_\nCandidate regex:\n$candidate_re\n\tgroup: $g +roup\n\tversion: $version\n}; } else { say qq{No candidate; orig:\n$_\n} } } exit 0; __END__ /ax/disks/xyz.prdenv.1/tool_utils/asda/15.2.0.5/asda.csh /tmp_log/site/disks/sad/tool_utr/zensxi/12.01.001a/log/script.pl /foo/bar/867.5309jenny/blonk.el /I/reject/your/reality/and/substitute/my/own
Original: /ax/disks/xyz.prdenv.1/tool_utils/asda/15.2.0.5/asda.csh Candidate regex: /ax/disks/xyz.prdenv.1/tool_utils/(?^ux:([^/]+?))/(?^ux:([^/]+?))/(?^u +:.*) group: asda version: 15.2.0.5 Original: /tmp_log/site/disks/sad/tool_utr/zensxi/12.01.001a/log/script.pl Candidate regex: /tmp_log/site/disks/sad/tool_utr/(?^ux:([^/]+?))/(?^ux:([^/]+?))/(?^u: +.*) group: zensxi version: 12.01.001a Original: /foo/bar/867.5309jenny/blonk.el Candidate regex: /foo/(?^ux:([^/]+?))/(?^ux:([^/]+?))/(?^u:.*) group: bar version: 867.5309jenny No candidate; orig: /I/reject/your/reality/and/substitute/my/own
The cake is a lie.
The cake is a lie.
The cake is a lie.
|
|---|