Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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":



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (7)
As of 2024-04-19 09:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found