Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^2: How do I reference repeated capture groups?

by kcott (Archbishop)
on Aug 13, 2022 at 03:03 UTC ( [id://11146135]=note: print w/replies, xml ) Need Help??


in reply to Re: How do I reference repeated capture groups?
in thread How do I reference repeated capture groups?

It's not specifically part of your question; however, it occurs to me that you might not want to capture all that excess leading and trailing whitespace. Compare these:

$ perl -E ' my $re = qr{(\w+)((?:\s*\d+\s*)*)}; my $str = "a 1 2 3 b 4 5 6"; while ($str =~ /$re/g) { say "|$&|: |$1| |$2|"; } ' |a 1 2 3 |: |a| | 1 2 3 | |b 4 5 6|: |b| | 4 5 6|
$ perl -E ' my $re = qr{(\w+)\s+((?:\s*\d+)*)}; my $str = "a 1 2 3 b 4 5 6"; while ($str =~ /$re/g) { say "|$&|: |$1| |$2|"; } ' |a 1 2 3|: |a| |1 2 3| |b 4 5 6|: |b| |4 5 6|

— Ken

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11146135]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (4)
As of 2024-03-29 08:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found