rovf has asked for the wisdom of the Perl Monks concerning the following question:
In both cases, the regexp succeed. In the first case, b+ picks up all four b's. In the second case, b* picks up zero b's. Why is + greedy in this example, but * is not? I try to find enlightment at perlre, but with no success.$ perl -lwe '"abbbbc"=~/(b+)/ && print "Found: $1"' Found: bbbb $ perl -lwe '"abbbbc"=~/(b*)/ && print "Found: $1"' Found:
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Greediness of * vs. greediness of +
by moritz (Cardinal) on Sep 08, 2010 at 09:29 UTC | |
|
Re: Greediness of * vs. greediness of +
by Marshall (Canon) on Sep 08, 2010 at 09:40 UTC | |
|
Re: Greediness of * vs. greediness of +
by ww (Archbishop) on Sep 08, 2010 at 13:00 UTC | |
by moritz (Cardinal) on Sep 08, 2010 at 13:07 UTC | |
by JavaFan (Canon) on Sep 08, 2010 at 13:57 UTC | |
|
Re: Greediness of * vs. greediness of +
by rovf (Priest) on Sep 08, 2010 at 10:21 UTC |