I have a string “region_2>0” where I want to replace _2 with string.empty using Regex.
My expression is ((_)[^_]*)\w(?=[\s=!><]) which in both Regulator and Expresso gives me _2. However, the code(c#):
Regex.Match(legacyExpression, "((_)[^_]*)\\w(?=[\\s=!><])").Value
gives me “_2>0”, which also causes the replace to be wrong (It returns “region” since removing the whole “_2>0” instead of “_2”. The result I want is “region>0”. Shouldn’t the code and the regex programs give the same results? And how can I get it to work?
(Note the string is not static, it could be in many different forms, but the rule is I want to replace the last _X in the string with string.empty.
Thanks!
I copied your code as is into the new project:
The output is
_2.