in reply to Regular expression
That assumes however that the strings used to anchor the parts that will be replaced won't never be also part of the text to be replaced - in your example, you migt have for example '+SqlNet=XXX+' instead of 'nasit' as password.use strict; use warnings; my $line = 'OPENINFO="Oracle_XA:Oracle_XA+Acc=P/NASIT/nasit+SesTm=60+S +qlNet=QANASIT+LogDir=/users/nas/disk1/data/traces+DB=QANASIT+Objects= +true+Threads=true"'; my $DBUser = '$DBUser'; my $DBPass = '$DBPass'; my $DBSid = '$DBSid'; my $openinfo_rx = qr/ \A OPENINFO=" # openinfo line start ( [^"]+ ) # whatever inside the '"'s " \z # openinfo line end /x; if ($line =~ m/$openinfo_rx/) { my $openinfo_content = $1; my $quoted_openinfo_content = quotemeta( $1 ); my (@openinfo_parts) = split( /$quoted_openinfo_content/, $line ); $openinfo_content =~ s{ =P/ # =P/ starts user/pass part ([^+]+) # whatever except + \+ # end mark for user/pass part } {=P/$DBUser/$DBPass+}x; $openinfo_content =~ s{ \+(SqlNet|DB)= # ([^+]+) # whatever except + \+ # end mark } {+$1=$DBSid+}xg; $line = join( $openinfo_content, @openinfo_parts); } print $line;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regular expression
by Noame (Beadle) on Nov 11, 2007 at 15:31 UTC | |
by Krambambuli (Curate) on Nov 11, 2007 at 16:39 UTC |