fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text.RegularExpressions;
  6.  
  7. public class Test
  8. {
  9. public static void Main()
  10. {
  11. var text = "$(string1$(string2)$sometexthere$(string3$(string4)$texttext)$anothertext)$";
  12. var pattern = @"(?=(?<result>\$\((?>[^()]+|(?<o>\()|(?<-o>\)))*(?(o)(?!))\)\$))";
  13. var results = Regex.Matches(text, pattern)
  14. .Cast<Match>()
  15. .Select(x => x.Groups["result"].Value)
  16. .ToList();
  17. foreach (var s in results)
  18. Console.WriteLine(s);
  19. }
  20. }
Success #stdin #stdout 0.09s 22436KB
stdin
Standard input is empty
stdout
$(string1$(string2)$sometexthere$(string3$(string4)$texttext)$anothertext)$
$(string2)$
$(string3$(string4)$texttext)$
$(string4)$