cosmicperl has asked for the wisdom of the Perl Monks concerning the following question:
I've just found a bug as this isn't doing what I expected. I thought the output would be:-my $text = "hello to all the perl monks"; while ($text =~ /\b([A-Za-z'\-]+ [A-Za-z'\-]+)\b/g) { print "$1\n"; }#while
But the output is actually:-hello to to all all the the perl perl monks
I was about to just run the regexp twice, removing the first word, but this seemed like a nasty fix. I'm guessing there is a better way to get the result I want?hello to all the perl monks
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Regexp matching words, not doing what I expect
by moritz (Cardinal) on May 13, 2009 at 18:11 UTC | |
by cosmicperl (Chaplain) on May 14, 2009 at 09:46 UTC | |
|
Re: Regexp matching words, not doing what I expect
by graff (Chancellor) on May 14, 2009 at 03:11 UTC | |
|
Re: Regexp matching words, not doing what I expect
by JavaFan (Canon) on May 13, 2009 at 19:36 UTC | |
by AnomalousMonk (Archbishop) on May 13, 2009 at 19:59 UTC | |
by JavaFan (Canon) on May 13, 2009 at 20:42 UTC | |
|
Re: Regexp matching words, not doing what I expect
by generator (Pilgrim) on May 13, 2009 at 18:05 UTC |