Thank You John and Anshul for response. It was great help. Regards, Ashish Srivastava
----- Original Message ---- From: Anshul Saxena <[EMAIL PROTECTED]> To: John W. Krahn <[EMAIL PROTECTED]> Cc: Perl Beginners <beginners@perl.org> Sent: Wednesday, 1 November, 2006 11:01:38 PM Subject: Re: Regular Expression Help Ashish , you might have the [ in a recurring sequence using [* On 11/1/06, John W. Krahn <[EMAIL PROTECTED]> wrote: > > Ashish Srivastava wrote: > > I have a string which have multiple placeholder, for example: > > > > $str = 'Hello [[Name]], Your login id is [[Login]] !!!"; > > > > I want to replace all placeholder with some identifier. In above > example: identifier are Name and Login. > > The regular expression for this requirment is pretty staightward: > > > > $str =~ s/\[\[([\d\w\-]+)\]\]/$1/g; > > > > Now the problem is there could be Nested Placeholders. For example: > > > > $str = 'Error is: [[[[id]]-[[message]]]]' > > > > so in above example if idenfiers are defined as: > > > > id = 1001 > > Message = "Crash" > > 1001-Crash = "System overloaded" > > > > so output of my required regular expression for subsitution should be: > > > > Error is: System overloaded > > $ perl -le' > my %t = ( > id => 1001, > message => "Crash", > "1001-Crash" => "System overloaded", > ); > > my $str = q/Error is: [[[[id]]-[[message]]]]/; > > print $str; > > 1 while $str =~ s/\[\[([\w-]+)]]/$t{$1}/g; > > print $str; > ' > Error is: [[[[id]]-[[message]]]] > Error is: System overloaded > > > > > John > -- > Perl isn't a toolbox, but a small machine shop where you can special-order > certain sorts of tools at low cost and in short order. -- Larry Wall > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > <http://learn.perl.org/> <http://learn.perl.org/first-response> > > > __________________________________________________________ Yahoo! India Answers: Share what you know. Learn something new http://in.answers.yahoo.com/