I have dictionary with key as pattern and replacement as value. Each pattern have one capturing group. I would like to replace ONLY capturing group with the replacement. My attempt is the following, but of course it's replacing whole pattern. I am limited to .NET 3.5. Not sure if I am on right track.
string xml = "abc def ghi blabla horse 123 jakljd alj ldkfj s;aljf kljf sdlkj flskdjflskdjlf lskjddhcn guffy";
Dictionary<string, string> substitutions = new Dictionary<string, string>
{
{"abc (.+) ghi", "AAA"},
{"kljf (.+) flskdjflskdjlf", "BBB"}
};
foreach(KeyValuePair<string, string> entry in substitutions)
{
xml = Regex.Replace(xml, entry.Key, delegate(Match m) { return m.Groups[1].Value; });
Console.WriteLine(xml);
}
The final string should like this:
"abc AAA ghi blabla horse 123 jakljd alj ldkfj s;aljf BBB sdlkj flskdjflskdjlf lskjddhcn guffy"