john john - 1 year ago 79
Perl Question

perl regex, replace each individual words with another one

I have a formulat like

(var1 - var2 ) + var3

I want to replace
var1 - var 3

(put(var1,format.) - put(var2, format.) + put(var3, format.)

what is the simplest way to do that with perl reg?


Answer Source
$string = '(var1 - var2 ) + var3';
$string  =~ s/\b(var\d+)\b/put($1, format.)/g;
print $string;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download