in reply to Behavior of /g when there are capture groups

my @groups = ( 'fo.', '.­*?', 'ba.' ); my $find = join '', @groups; my $capture = join '', map "($_)", @groups; my $fc = read_my_file(); my @excerpts = $fc =~ /$find/g; my @parts = $excerpts[0] =~ /$capture/;

[Updated: Changed [ ... ] to ( ... ) on the first line -- thanks for the private correction.]

- tye        

Replies are listed 'Best First'.
Re^2: Behavior of /g when there are capture groups (join)
by ExReg (Priest) on Apr 21, 2016 at 15:31 UTC

    Nice succinct way of constructing the two regexes from one source. I think that may do the trick.