http://qs321.pair.com?node_id=11118153


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]
  • Comment on Re: How to access last capture groups outside regex using interpolation but w/o using re 'eval'?
  • Select or Download Code

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!