I have string as below,
string str = "FX(Y + 1, -(5 * 10) + FML("Test - KB")";
I would like to replace the “-” with “-1 * “. However it should not apply to literal string. For example. FML(“Test – KB”) should NOT be changed to FML(“Test -1 * KB”).
The desired output is “FX(Y + 1, -1 * (5 * 10) + FML(“Test – KB”)”.
Is there a way to do this in regular expression?
Any advice/help is much appreciated.
It will look something like this:
Regex explanation:
Output for your example string is:
(Note that this doesn’t handle string escapes, if they are supported in your target language.)
This solution will handle strings properly, not just with a heuristic. Here is an example:
Becomes:
Note that the string is not touched even though it “looks like” the other parts.