using System;
using System.Linq;
using System.Text.RegularExpressions;
public class Test
{
public static void Main()
{
var text = "(1 * (2 - 3)) + 4";
var pattern = @"(?=(\((?>[^()]+|(?<c>)\(|(?<-c>)\))*(?(c)(?!))\)))";
var results = Regex.Matches(text, pattern)
.Cast<Match>()
.Select(m => m.Groups[1].Value)
.ToList();
Console.WriteLine(String.Join(", ", results));
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uTGlucTsKdXNpbmcgU3lzdGVtLlRleHQuUmVndWxhckV4cHJlc3Npb25zOwpwdWJsaWMgY2xhc3MgVGVzdAp7CglwdWJsaWMgc3RhdGljIHZvaWQgTWFpbigpCgl7CgkJdmFyIHRleHQgPSAiKDEgKiAoMiAtIDMpKSArIDQiOwoJCXZhciBwYXR0ZXJuID0gQCIoPz0oXCgoPz5bXigpXSt8KD88Yz4pXCh8KD88LWM+KVwpKSooPyhjKSg/ISkpXCkpKSI7CgkJdmFyIHJlc3VsdHMgPSBSZWdleC5NYXRjaGVzKHRleHQsIHBhdHRlcm4pCgkJCS5DYXN0PE1hdGNoPigpCgkJCS5TZWxlY3QobSA9PiBtLkdyb3Vwc1sxXS5WYWx1ZSkKCQkJLlRvTGlzdCgpOwoJCUNvbnNvbGUuV3JpdGVMaW5lKFN0cmluZy5Kb2luKCIsICIsIHJlc3VsdHMpKTsKCX0KfQ==