fork(5) download
  1. using System;
  2. using System.Text.RegularExpressions;
  3.  
  4. public class Test
  5. {
  6. public static void Main()
  7. {
  8. String input = @"[[Parent1 [[Child 1]],[[Child 2]],[[Child 3]]]] [[Parent2 [[Child 1]],[[Child 2]]]]";
  9. Regex rgx = new Regex(@"(?<=^|]\s)\[\[(?<item>\S+)|(?<children>\[\[(?!Parent).*?\]\])(?=]]\s|]]$)");
  10. foreach (Match m in rgx.Matches(input))
  11. {
  12. Console.WriteLine(m.Groups[1].Value);
  13. Console.WriteLine(m.Groups[2].Value);
  14. }
  15. }
  16. }
Success #stdin #stdout 0.07s 34168KB
stdin
Standard input is empty
stdout
Parent1


[[Child 1]],[[Child 2]],[[Child 3]]
Parent2


[[Child 1]],[[Child 2]]