using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text.RegularExpressions; public class Test { public static void Main() { var text = "$(string1$(string2)$sometexthere$(string3$(string4)$texttext)$anothertext)$"; var pattern = @"(?=(?\$\((?>[^()]+|(?\()|(?<-o>\)))*(?(o)(?!))\)\$))"; var results = Regex.Matches(text, pattern) .Cast() .Select(x => x.Groups["result"].Value) .ToList(); foreach (var s in results) Console.WriteLine(s); } }