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>