Dear all,

I am trying the following code using ActivePerl 5.6.1.626, in my quest to
find the minimal string between "bar" and "river":

$stt="The food is under the bar in the barn in the river.";
$stt=~/bar(.*?)river/;
print "$&";

The output is:
bar in the barn in the river

Instead of the expected: 
barn in the river

guaranteed by the question mark that follows the star. In fact, the question
mark does not affect the output at all.
It seems to me that the greediness of the search expresion is only valid if
the string that you want to match shrinks from left to right, like looking
for the minimal match between "food" and "in", like in the following code:

$stt="The food is under the bar in the barn in the river.";
$stt=~/food(.*?)in/;
print "$&";

Which prints correctly:
food is under the bar in


Can anyone explain this, please?

Best regards,

Daniel Bornaz
GBS Specialist
~~~~~~~~~~~~~~~~~~~~~~~~~~
 Compaq Computer Romania
   77 Emanoil Porumbaru St.
   Bucharest Romania
   Tel.: +401 222 23 24
   Fax : +401 223 40 10
~~~~~~~~~~~~~~~~~~~~~~~~~~~

Reply via email to