fork(1) download
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. public class Test
  5. {
  6. public static void Main()
  7. {
  8. string msg= "{1,{Cat,{Blue,1}},2,{Dog,5}}";
  9. msg = msg.Substring(1, msg.Length - 2);
  10. string[] charSetOccurences = Regex.Split(msg, @",(?=[^{}]*(?:(?:(?'O'{)[^{}]*)+(?:(?'-O'})[^{}]*?)+)*(?(O)(?!))$)");
  11. foreach (string s in charSetOccurences)
  12. {
  13. Console.WriteLine(s);
  14. }
  15. }
  16. }
Success #stdin #stdout 0.08s 34192KB
stdin
Standard input is empty
stdout
1
{Cat,{Blue,1}}
2
{Dog,5}