fork 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 str = "((1+2)*(4+3))";
  12. var pattern = @"(?=(\((?>[^()]+|(?<o>)\(|(?<-o>)\))*(?(o)(?!)|)\)))";
  13. var result = Regex.Matches(str, pattern)
  14. .Cast<Match>()
  15. .Select(x => x.Groups[1].Value);
  16. Console.WriteLine(string.Join("\n", result));
  17. }
  18. }
Success #stdin #stdout 0.04s 134592KB
stdin
Standard input is empty
stdout
((1+2)*(4+3))
(1+2)
(4+3)