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.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|