kannan

kannan

  • NA
  • 1
  • 1.3k

Need regex code to replace a particular variable name in an expression by some value.

Aug 11 2012 1:16 PM
A variable name can contain the characters [a-zA-Z0-9_]
I want to replace all occurences of a particular variable name in an expression by some value.
For example if the expression is a+aa-b and I want to replace the variable "a" by 1. The variable "aa" should not get replaced.
The regex has to remember the unmatched portions, so that they can be copied over in the final expression. I need to get this done as part of a bigger project and don't have the time to read up in depth about regex. Please help.

Answers (1)