regular expression match question




A script like this:

line1: $string3 = "bacdeabcdefghijklabcdeabcdefghijkl";
line2: $string4 = "xxyyzzbatttvv";

line3: print "\$1 = $1 \@{$-[0],$+[0]}, \$& = $&\n" if($string3
=~ /(a|b)*/);
line4: print "\$1 = $1 \@{$-[0],$+[0]}, \$& = $&\n" if($string4
=~ //);

Run and gett result:

$1 = a @{0,2}, $& = ba
$1 = @{0,0}, $& =


If I change the code of line3 to:

print "\$1 = $1 \@{$-[0],$+[0]}, \$& = $&\n" if($string3 =~
/(a|b)+/);

and keep everything else the same, I will get:

$1 = a @{0,2}, $& = ba
$1 = a @{6,8}, $& = ba


This result doesn't look very promising to me. The first matching
results keeps the same
between * and +, while the second who is supposed to inherit the
pervious match shows
different result.

The version I'm using is 5.6.1. Can anyone tell why is this? A bug? Or
some tricky I can't
figure out? Does this work differently in latest release?

Thanks.

Sincerely
Pine



Relevant Pages