Guffa should answer your question, I just want to share my alternative way to solve your problem, using more features from .NET Regex (if I understand your problem correctly):
int i = 1;
string input = "FGS1=(B+A*10)+A*10+(C*10.5)";
var lookUp = new Dictionary<string, string>();
var output = Regex.Replace(input,
"([A-Z][A-Z\\d]*)",
m => {
if(!lookUp.ContainsKey(m.Value))
{
lookUp[m.Value] = "i" + i++;
}
return lookUp[m.Value];
});
Console.WriteLine(output);
I use a dictionary to track duplicate matches
This should work even if your repetition is different from "A". In your original solution, it is checked specifically for "A", which is rather fragile.
source
share