fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5.  
  6. public class Test
  7. {
  8. public static void Main()
  9. {
  10. var text = "[tex1] [text [2]]";
  11. var pattern = @"\[((?>[^][]+|(?<o>)\[|(?<-o>]))*)]";
  12. var results = Regex.Matches(text, pattern);
  13. foreach (Match match in results)
  14. {
  15. Console.WriteLine($"Group 2: {match.Groups[1].Value}");
  16. }
  17. }
  18. }
Success #stdin #stdout 0.07s 27792KB
stdin
Standard input is empty
stdout
Group 2: tex1
Group 2: text [2]