Anish Kumar K. wrote:
Hi
Please anyone help me in Reg Exp. I wanted to replace "[%one_two%]" and "[%pne%]" with the value
"New" say...
I wrote the following code...I am unable to get the output as
"This is a test for New number and New numbers."
I am getting it as
"This a test for New numbers." WHICH IS WRONG...
Please let me know what to do If I need to replace in both...
Thanks
Anish
#!/usr/bin/perl
$openTag='\[%';
$closeTag='%\]';
my $count=0;
$_= "This is a test for [%one_two%] number and [%pne%] numbers.";
s/$openTag.*$closeTag/New/g;
print "The new line is:::::: $_ \n";
.* is greedy and will match from the first $openTag til the last $closeTag,
from here ->[%one_two%] number and [%pne%]<- to here. Use .*? instead,
it is non-greedy and will match from here ->[%one_two%]<- to here and
from here ->[%pne%]<- to here. I can recommed Mastering Regular Expressions
form O'Reilly if you want to learn more.
--
Flemming Greve Skovengaard The prophecy of the holy Norns
a.k.a Greven, TuxPower The world is doomed to die
<[EMAIL PROTECTED]> Fire in the sky
4112.38 BogoMIPS The end is coming soon
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>