using System.Text.RegularExpressions;
public static void Main()
string pattern = @"(?<g1>{NUM})|(?<g2>{\d*NUM})|(?<g3>{NUM\d*})";
string input = "The quick brown fox {NUM} jumped over {211NUM} the lazy dog {NUM}. The Quick brown fox {NUM10} jumped over the lazy dog. ";
Console.WriteLine("*** Simple replace:");
string output = Regex.Replace(input, pattern, "{CHANGED ${g1}${g2}${g3}}");
Console.WriteLine(output);
Console.WriteLine("*** Replace with MatchEvaluator:");
output = Regex.Replace(input, pattern, delegate(Match match)
if (match.Groups["g1"].Success)
if (match.Groups["g2"].Success)
if (match.Groups["g3"].Success)
Console.WriteLine(output);