dlw has asked for the wisdom of the Perl Monks concerning the following question:
Produces the following output: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;
What I want to see is this, where a character already matched can appear in a different context:bash> perl resample.pl A plus B D plus E 2 plus F H plus I 4 plus J 5 plus K
What magic do I need to add to the regular expression to get this result? Thanks oh wise Monks.A plus B D plus E E plus F H plus I I plus J J plus K
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Regular Expression rematch
by ikegami (Patriarch) on Aug 16, 2009 at 01:56 UTC | |
by AnomalousMonk (Archbishop) on Aug 16, 2009 at 02:07 UTC | |
by ikegami (Patriarch) on Aug 16, 2009 at 02:50 UTC | |
by ig (Vicar) on Aug 16, 2009 at 05:43 UTC | |
by ikegami (Patriarch) on Aug 16, 2009 at 06:04 UTC | |
| |
by AnomalousMonk (Archbishop) on Aug 16, 2009 at 06:05 UTC |