Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Greedy quantifiers

use strict;
use warnings;

'xaaab' =~ /xa*/;
print "$&\n";

'xabxaab' =~ /xa*/;
print "$&\n";

'xabxaab' =~ /a*/;
print "$&\n";

/xa*/ on xaaab      xaaa  because it is greedy
/xa*/ on xabxaab    xa at the beginning even though the other  one is longer
/a*/  on xabxaab    the empty string at the beginning of the string