using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text.RegularExpressions; public class Test { public static void Main() { string InputText = "12/03/2015 *** [RandomText] // 1.04.1112V"; string regex = @"([0-9/]*) \*\*\* \[([A-Za-z]*)\] \/\/ (.*)"; string Name = "GoogleChrome"; string OutputPattern1 = "{1} - {Name} version {4}"; string OutputPattern2 = "{Name}_{3}"; string rx = @"{(?:(\d+)|Name)}"; var match = Regex.Match(InputText, regex); if (match.Success) { Console.WriteLine( Regex.Replace(OutputPattern1, rx, x=> !x.Groups[1].Success ? Name: int.Parse(x.Groups[1].Value) < match.Groups.Count ? match.Groups[int.Parse(x.Groups[1].Value)].Value : x.Value) ); } } }