using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; public class Test { public static void Main() { var text = "[tex1] [text [2]]"; var pattern = @"\[((?>[^][]+|(?)\[|(?<-o>]))*)]"; var results = Regex.Matches(text, pattern); foreach (Match match in results) { Console.WriteLine($"Group 2: {match.Groups[1].Value}"); } } }