Hi Anish,

.* always tries to match as much as possible.

So the code you have sent takes the first [% and the last %] and
replaces everything in between.

If the contents in between the openTag and the closeTag is ONLY "word
characters" (i.e., _, 0-9, a-z, A-Z) then you may change the regEx to

s/$openTag\w+$closeTag/New/g;

With Best regards,
R. Kamal Raj Guptha.


>-----Original Message-----
>From: Anish Kumar K. [mailto:[EMAIL PROTECTED]
>Sent: Thursday, October 07, 2004 3:45 PM
>To: beginners perl
>Subject: Need Help
>
>
>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";
>



Confidentiality Notice

The information contained in this electronic message and any attachments to this 
message are intended
for the exclusive use of the addressee(s) and may contain confidential or privileged 
information. If
you are not the intended recipient, please notify the sender at Wipro or [EMAIL 
PROTECTED] immediately
and destroy all copies of this message and any attachments.

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