Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: How to access last capture groups outside regex using interpolation but w/o using re 'eval'?

by tybalt89 (Monsignor)
on Jun 16, 2020 at 23:24 UTC ( [id://11118153]=note: print w/replies, xml ) Need Help??


in reply to How to access last capture groups outside regex using interpolation but w/o using re 'eval'?

#!/usr/bin/perl use strict; # https://perlmonks.org/?node_id=11118150 use warnings; while( <DATA> ) { my @sizes = split ' ', <DATA>; my $regex = join '', map { "(?=(.))(\\g{-2}{$_})\\g{-2}*.*?" } @size +s; my @groups = ( /$regex/ )[ map 2 * $_ + 1, 0 .. $#sizes ]; print "[@groups]\n"; } __DATA__ cbaa 1 2 cba 1 bbaa 1 2 cccqrrtaaa 2 2 2 cccqrrtaaa 1 1 2 2 cccqrrtaaa 1 1 1 1 3

Outputs:

[c aa] [c] [b aa] [cc rr aa] [c q rr aa] [c q r t aaa]

Replies are listed 'Best First'.
Re^2: How to access last capture groups outside regex using interpolation but w/o using re 'eval'?
by rsFalse (Chaplain) on Jun 17, 2020 at 07:02 UTC
    Thanks! Crafty solution!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (7)
As of 2024-03-28 22:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found