John W. Krahn wrote:
Ramprasad wrote:

if I have
my $str = 'aw bcdefaw e a rt zzz kjkjkjaw qa' ;

If I wish to replace everything between 'a' and 'zzz' With 'TXT'
I do

$str=~s/a[^a]+zzz/aTXTzzz/;
This works fine.

Now if I wish to replace everything between 'aw' and 'zzz' with 'TXT'
I am not able to use

$str=~s/aw[^(aw)]+zzz/awTXTzzz/;

I know I can use
$str=~s/^(.*)aw.*?zzz/$1awTXTzzz/s;

But this seems to be a very untidy way beacuse In my real program $str
is an entire file in a string and could be a very long one

Is there a better way


You can use positive look-behind and positive look-ahead:

$ perl -e'
my $str = q/aw bcdefaw e a rt zzz kjkjkjaw qa/; print "$str\n";
$str =~ s/(?<=\ba\b).*?(?=\bzzz\b)/TXT/;
print "$str\n";
'
aw bcdefaw e a rt zzz kjkjkjaw qa
aw bcdefaw e aTXTzzz kjkjkjaw qa




Now How do I replace everything between the innermost 'aw' and 'zzz'?


Ram



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



Reply via email to