I think I prefer roboticus's alternate suggestion to extract complete ULRs first, then extract the filename from each URL, but if it absolutely must be done "in one line", this might serve (Perl version 5.10+ needed for state built-in, but this could be an ordinary my variable in the for-loop outside the if statement):

>perl -wMstrict -le "use 5.010; ;; use List::MoreUtils qw(part); ;; my $rx = qr{ \b ([[:alpha:]]+ (\d+)) \b }xms; ;; for my $s ( 'foo abc333 bar de4444 baz fghi22 xyzzy jk123 z', 'zzz123 xx yyyy12 xx xx1234', ) { if (my @matches = part { state $i = 0; $i++ % 2 } $s =~ m{ $rx }xm +sg) { print qq{matched: full (@{$matches[0]}); digits (@{$matches[1]})} +; } else { print 'no matches'; } } " matched: full (abc333 de4444 fghi22 jk123); digits (333 4444 22 123) matched: full (zzz123 yyyy12 xx1234); digits (123 12 1234)

See List::MoreUtils::part.


In reply to Re: multiple matches per line *AND* multiple capture groups per match by AnomalousMonk
in thread multiple matches per line *AND* multiple capture groups per match by Special_K

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.