Filip Jursik schreef:

> $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"

The match starts at the first possible position, or in other words: *?
doesn't look back.

To match the last 'first' in a series of 'first's, you need to express
that you don't allow a 'first' after it.

One way to do that:

perl -le '
  $_ = q{first first second third} ;
  print /(first(?!.*first).*third)/
'

but that would fail with q{first first second third first}

-- 
Affijn, Ruud

"Gewoon is een tijger."



-- 
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