On Fri, 2006-06-30 at 23:04 +0200, Filip Jursik wrote:
> Hi,
> 
> this
> 
> $text = "first first second third";
> $text =~ /(first.*?third)/;
> print $1;
> 
> gives me
> 
> "first first second third"
> 
> as a result instead of expected
> 
> "first second third"
> 
> What am I doing wrong? I've expected the .*? to limit the wildcard only to 
> the 
> string " second ".

I don't have the precise answer for you but I do know what is wrong. The
way regex' match is they start at character 0 and start attempting to
match your expression by reading one additional character until they get
to the end of the string. If the end of the string is reached without a
match, it starts over at character 1, expanding one character at a time.
It repeats this process until it either matches, or tries every
possibility. There are examples in the archives about how to overcome
this. However, I am unable to find them at the moment.

I'm sorry for not having the real answer to your question.

-- 
Joshua Colson <[EMAIL PROTECTED]>


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to