Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

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

by tybalt89 (Prior)
on Jun 16, 2020 at 23:24 UTC ( #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]
  • 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 (Hermit) on Jun 17, 2020 at 07:02 UTC
    Thanks! Crafty solution!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2020-10-26 19:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (252 votes). Check out past polls.

    Notices?