fork download
  1. using System;
  2. using System.Text.RegularExpressions;
  3. public class Test
  4. {
  5. public static void Main()
  6. {
  7. string msg= "(((a) or (b) or (c)) and ((d) or (e)) and ((!f) or (!g)))";
  8. var charSetOccurences = new Regex(@"\(((?:[^()]|(?<o>\()|(?<-o>\)))+(?(o)(?!)))\)");
  9. var charSetMatches = charSetOccurences.Matches(msg);
  10. foreach (Match mainMatch in charSetMatches)
  11. {
  12. var sets = charSetOccurences.Matches(mainMatch.Groups[1].Value);
  13. foreach (Match match in sets)
  14. {
  15. Console.WriteLine(match.Groups[0].Value);
  16. }
  17. }
  18. }
  19. }
Success #stdin #stdout 0.08s 34160KB
stdin
Standard input is empty
stdout
((a) or (b) or (c))
((d) or (e))
((!f) or (!g))