Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
Outputs:$string="abc de fgh ijkl"; while($string =~ /([a-z]+ [a-z]+)/g) { print "$1 $1\n"; }
I would like it to output:abc de fgh ijkl
I have tried doing:abc de de fgh fgh ijkl
and using lookarounds but I haven't been able to find the right combination of \G, lookarounds and matching to come out with what I want. I am also aware that I could just do:$string =~ /([a-z]+) ([a-z]+)\G(?: [a-z])*?/g
I trying to stick to regex's. Thanks, Alexmy @words =split $string; for($i=0;$i<$#words;$i++) { print "$words[$i] $words[$i+1]\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Combinatorial regexing
by blokhead (Monsignor) on May 04, 2007 at 18:36 UTC | |
|
Re: Combinatorial regexing
by johngg (Canon) on May 04, 2007 at 22:27 UTC | |
|
Re: Combinatorial regexing
by shandor (Monk) on May 04, 2007 at 19:15 UTC |