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.


In reply to Re: Regex creation by Fletch
in thread Regex creation by ovedpo15

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.