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 block = @"[-+]?\d+#(?:[-+]?\d*\.?\d+|~)"; // Block/unit pattern
  12. var pattern = $@"(?<=^(?:{block},\s)*){block}(?=(?:,\s{block})*$)";
  13. //Console.WriteLine(pattern);
  14. var results1 = Regex.Matches("3#0.01, 2#0.5, 1#-10, -2#~", pattern)
  15. .Cast<Match>().Select(x => x.Value);
  16. if (results1.Count() > 0)
  17. Console.WriteLine(string.Join(", ", results1));
  18. var results2 = Regex.Matches("MISTAKE3#0.01, 2#0.5, 1#-10, -2#~AND_HERE_MISTAKE_TOO", pattern)
  19. .Cast<Match>().Select(x => x.Value);
  20. if (results2.Count() > 0)
  21. Console.WriteLine(string.Join(", ", results2));
  22. }
  23. }
Success #stdin #stdout 0.04s 134592KB
stdin
Standard input is empty
stdout
3#0.01, 2#0.5, 1#-10, -2#~