16,718
社区成员
发帖
与我相关
我的任务
分享
void Main()
{
string str = @"(x+56*78*(45+6)+9/(x^2+3*(x+6)))+(x^3+6)-58+(x*(x-7))";
foreach(Match m in Regex.Matches(str,@"\((?>[^()]+|\((?<Open>)|\)(?<-Open>))*(?(Open)(?!))\)"))
{
Console.WriteLine(m.Value);
}
/*
(x+56*78*(45+6)+9/(x^2+3*(x+6)))
(x^3+6)
(x*(x-7))
*/
}