fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text.RegularExpressions;
  6.  
  7. public class Test
  8. {
  9. public static void Main()
  10. {
  11. string InputText = "12/03/2015 *** [RandomText] // 1.04.1112V";
  12. string regex = @"([0-9/]*) \*\*\* \[([A-Za-z]*)\] \/\/ (.*)";
  13. string Name = "GoogleChrome";
  14. string OutputPattern1 = "{1} - {Name} version {4}";
  15. string OutputPattern2 = "{Name}_{3}";
  16. string rx = @"{(?:(\d+)|Name)}";
  17. var match = Regex.Match(InputText, regex);
  18. if (match.Success) {
  19. Console.WriteLine(
  20. Regex.Replace(OutputPattern1, rx, x=>
  21. !x.Groups[1].Success ? Name:
  22. int.Parse(x.Groups[1].Value) < match.Groups.Count ?
  23. match.Groups[int.Parse(x.Groups[1].Value)].Value :
  24. x.Value)
  25. );
  26. }
  27. }
  28. }
  29.  
Success #stdin #stdout 0.08s 29588KB
stdin
Standard input is empty
stdout
12/03/2015 - GoogleChrome version {4}