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. var text = "cov('Age', ['5','7','9'])";
  12. var results = Regex.Matches(text, @"\[([^][]+)]")
  13. .Cast<Match>()
  14. .Select(x => x.Groups[1].Value.Split('\'', ',').Where(c => !string.IsNullOrEmpty(c)));
  15. foreach (var s in results)
  16. Console.WriteLine(string.Join(" and ", s));
  17.  
  18. var results1 = Regex.Matches(text, @"\[([^][]+)]")
  19. .Cast<Match>()
  20. .Select(x => Regex.Matches(x.Groups[1].Value, @"\d+"));
  21. foreach (var s in results1)
  22. Console.WriteLine(string.Join(" and ", s));
  23.  
  24. var results2 = Regex.Matches(text, @"(?<=\[[^][]*)\d+(?=[^][]*])").Cast<Match>().Select(x => x.Value);
  25. Console.WriteLine(string.Join(" and ", results2));
  26.  
  27. }
  28. }
Success #stdin #stdout 0.06s 22080KB
stdin
Standard input is empty
stdout
5 and 7 and 9
5 and 7 and 9
5 and 7 and 9