I need some Perl regular expression help. The following snippet of code:
use strict;
use warnings;
my $str = "In this example, A plus B equals C, D plus E plus F equals G and H plus I plus J plus K equals L";
my $word = "plus";
my @results = ();
1 while $str =~ s/(.{2}\b$word\b.{2})/push(@results,"$1\n")/e;
print @results;
Produces the following output:
A plus B D plus E 2 plus F H plus I 4 plus J 5 plus K
What I want to see is this, where a character already matched can appear in a new match in a different context:
A plus B D plus E E plus F H plus I I plus J J plus K
How do I change the regular expression to get this result? Thanks --- Dan