fork(1) 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 pattern = "^{(?:(?<c>[^{}]+)|(?<o>{)|(?<-o>}))*(?(o)(?!))}$";
  12. var result = Regex.Matches("{a{bb{ccc{dd}}}}", pattern)
  13. .Cast<Match>().Select(p => p.Groups["c"].Captures)
  14. .ToList();
  15. foreach (var coll in result)
  16. foreach (var v in coll)
  17. Console.WriteLine(v);
  18. }
  19. }
Success #stdin #stdout 0.04s 134784KB
stdin
Standard input is empty
stdout
a
bb
ccc
dd