fork(10) download
  1. using System;
  2. using System.Text.RegularExpressions;
  3. using System.IO;
  4. using System.Linq;
  5. public class Test
  6. {
  7. public static void Main()
  8. {
  9. var input = "abc(test)def(rst(another test)uv)xy";
  10. var regex = new Regex(@"(?=(\(([^()]+| (?<Level>\()| (?<-Level>\)))+(?(Level)(?!))\)))", RegexOptions.IgnorePatternWhitespace);
  11. var results = regex.Matches(input).Cast<Match>()
  12. .Select(p => p.Groups[1].Value)
  13. .ToList();
  14. Console.WriteLine(String.Join(", ", results));
  15. }
  16. }
Success #stdin #stdout 0.12s 24376KB
stdin
Standard input is empty
stdout
(test), (rst(another test)uv), (another test)