Walter, I have not tested this but I believe your problem is the greedy matching. It is matching from one { to the furthest } it can. I am guessing that \w is matching those internal }{ and the $ which I don't think it should but they might be ignored because they are generally meta characters. I would try adding the ? to switch to non-greedy matching and see where that gets you. i.e. (\w+?)
Matt -----Original Message----- From: perl-unix-users-boun...@listserv.activestate.com [mailto:perl-unix-users-boun...@listserv.activestate.com] On Behalf Of walter.l...@schwindt.eu Sent: Tuesday, December 08, 2009 10:07 To: perl-unix-users@listserv.ActiveState.com Subject: [Perl-unix-users] Need help for regular expression problem Hello, I have the following strings: TEST1=/bla/\${var1}/bla/${var2}a${var3}/bla TEST2=/bla/\${var1}/bla/${var2}${var3}/bla I want to transform them: TEST1=/bla/\$ENV{var1}/bla/$ENV{var2}a$ENV{var3}/bla TEST2=/bla/\$ENV{var1}/bla/$ENV{var2}$ENV{var3}/bla The rule: substitute all $var to $ENV{var}, but not if the character before $ is a \ (backslash). My solution works fine with TEST1 but not with TEST2: s/(^|[^\\]?)\$\{(\w+)\}/$1\$ENV\{$2\}/g; I get: TEST1=/bla/\$ENV{var1}/bla/$ENV{var2}a$ENV{var3}/bla TEST2=/bla/\$ENV{var1}/bla/$ENV{var2}{var3}/bla The problem occure, if no character is between two variables. Some ideas? Thanks, Walter _______________________________________________ Perl-Unix-Users mailing list Perl-Unix-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs _______________________________________________ Perl-Unix-Users mailing list Perl-Unix-Users@listserv.ActiveState.com To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs