in reply to Re^4: Perl RE; how to capture, and replace based on a block?
in thread Perl RE; how to capture, and replace based on a block?
just a quick example on greedy and non greedy quantifiers, under the Perl debugger:
As you can see the default "*" quantifier is greedy, so that the regex tries to match as much as possible. Using the modified "*?" quantifier, the regex becomes non greedy. You will see the same type of result if you try the "+" and the "+?" quantifiers.
DB<1> $string = "foo bar foo bar foo";
DB<2> x $string =~ /(fo.*ar)/
0 'foo bar foo bar'
DB<3> x $string =~ /(fo.*?ar)/
0 'foo bar'