On Wed, 13 Jun 2001 11:12:05 +0200, Allan Juul wrote:
>am i going totally blind or?
>from the snip below i want to output just:
>aaa
>aaa
>
>what i get is :
>aaa
>aaa
> 333 444<END>
>
>
>why is that?
>tnanks
>allan
>
>
>#!perl
>$str = "aaa 111 222 aaa 333 444<END>";
>output($str);
>sub output{
> $text = $_[0];
> $text =~ s/.*?(aaa).*?/$1\n/ig;
> print $text;
>}
You ask for minimal matching. Well, minimal, on the right side, is
matching nothing at all. So
s/.*?(aaa).*?/$1\n/ig;
is equivalent to
s/.*?(aaa)/$1\n/ig;
What can you do? Drop the .*? on the right. macke the thing match "aaa"
or the end of string. Replace with "$1\n" if something was matched, or
with nothing if it matched the end of string. Like:
s/.*?(aaa|$)/length $1?"$1\n":""/ige;
--
Bart.