fork download
  1. using System;
  2. using System.Linq;
  3. using System.Text.RegularExpressions;
  4. public class Test
  5. {
  6. public static void Main()
  7. {
  8. var text = "(1 * (2 - 3)) + 4";
  9. var pattern = @"(?=(\((?>[^()]+|(?<c>)\(|(?<-c>)\))*(?(c)(?!))\)))";
  10. var results = Regex.Matches(text, pattern)
  11. .Cast<Match>()
  12. .Select(m => m.Groups[1].Value)
  13. .ToList();
  14. Console.WriteLine(String.Join(", ", results));
  15. }
  16. }
Success #stdin #stdout 0.09s 30868KB
stdin
Standard input is empty
stdout
(1 * (2 - 3)), (2 - 3)