fork(1) download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5.  
  6. public class Test
  7. {
  8. public static void Main()
  9. {
  10. Regex re = new Regex(
  11. @"([^(]+|"+
  12. @"\([^(]*(?:\([^(]*(?:\([^(]*\)[^(]*)*\)[^(]*)*\)"+
  13. @")"
  14. ); // Closes capture group
  15. string sInput = "herpdediderp (orange,(hmm)) some other crap (red,hmm)"+
  16. "buzz (blue,(hmmm) (damn) derp) (hi)";
  17. List<string> sResult = re.Split(sInput).Where(s => !string.IsNullOrWhiteSpace(s)).ToList();
  18.  
  19. Console.WriteLine("1:" + string.Join("\n", sResult));
  20.  
  21. sInput = "herpdediderp (orange,(hmm)) some other crap (red,hmm)"+
  22. "buzz (blue,((hmmm) (damn) derp)) (hi)";
  23. sResult = re.Split(sInput).Where(s => !string.IsNullOrWhiteSpace(s)).ToList();
  24.  
  25. Console.WriteLine("2:" + string.Join("\n", sResult));
  26. }
  27. }
Success #stdin #stdout 0.06s 20484KB
stdin
Standard input is empty
stdout
1:herpdediderp 
(orange,(hmm))
 some other crap 
(red,hmm)
buzz 
(blue,(hmmm) (damn) derp)
(hi)
2:herpdediderp 
(orange,(hmm))
 some other crap 
(red,hmm)
buzz 
(blue,((hmmm) (damn) derp))
(hi)