in reply to ZERO_LENGTH match

What do you with the matches not being the same?
$_ = 'aaabbb'; while (/((?: a | c? )*)/xg) { printf "1: '%s' '%d'\n", $&, pos; } while (/(( a )* | ( c? )?)/xg) { printf "2: '%s' '%d'\n", $&, pos; } __END__ 1: 'aaa' '3' 1: '' '3' 1: '' '4' 1: '' '5' 1: '' '6' 2: 'aaa' '3' 2: '' '3' 2: '' '4' 2: '' '5' 2: '' '6'

Replies are listed 'Best First'.
Re^2: ZERO_LENGTH match
by sh1tn (Priest) on Aug 01, 2005 at 15:52 UTC
    Without 'g' modifier:
    1.>perl -e 'use re(debug); $_ = 'aaabbb'; /(( a | c? )*)/x' 2.>perl -e 'use re(debug); $_ = 'aaabbb'; /(( a )* | ( c? )?)/x'