t.pl:

#!/usr/bin/perl -w

my $str =
'aaa
--%%
b%b
%%--
ccc
--%%ddd%%--';

$str =~ s/--\%\%.*?\%\%--/--\%\%\%\%--/sg;

print $str, "\n";

--------------

hacksaw > perl t.pl
aaa
--%%%%--
ccc
--%%%%--

--------------

All the magic is in the matching operator.

The ? after the .* makes it match the smallest possible set, rather than the 
largest, i.e. it makes it "non-greedy"

The s at the end makes it match newlines as well as everything else.

The g at the end says to keep looking to do the substitution until you hit the 
end of the string.


-- 
In the creative act, the Creation continues.
http://www.hacksaw.org -- http://www.privatecircus.com -- KB1FVD



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to