using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text.RegularExpressions; public class Test { public static void Main() { var s = "Hello\nabc\nHello\ndef\nHello"; var i = 0; var result = Regex.Replace(s, "Hello", m => string.Format("{0}{1}",m.Value,++i), RegexOptions.IgnoreCase); Console.WriteLine(result); } }