On May 31, 3:02 pm, [EMAIL PROTECTED] (Sharan Basappa) wrote: > I seem to be having some conceptual problem with greedy quantifiers .. > My understanding is that it matches as much as follows while still > allowing rest of the > regex to match. > But look at the following example : > $str = mississippi; > $str =~ m/m(.*i)(.*pi)/; > print "one is $1 \n"; > print "two is $2 \n"; > > $str = mississippi; > $str =~ m/m(.*i?)(.*pi)/; > print "one is $1 \n"; > print "two is $2 \n"; > > In the first code snippet, I expected first regex (.*i) to match till > ississip and leave pi for (.*pi) regex. > > But what I get as the output of this script is : > > one is ississi > two is ppi > one is ississip > two is pi > > Why is that perl is leaving ppi to second regex while it can continue > till first p in ppi and can still get the second regex to get a match > ? > $str =~ m/m(.*i)(.*pi)/;
m - matches m (.*i) - matched ississi. ( IF u want to match p of ppi u will have to write (.*i.)) -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/