using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text.RegularExpressions; public class Test { public static void Main() { var line = "this is (a (string))"; var pattern = @"\(((?>[^()]+|\((?)|\)(?<-o>))*(?(o)(?!)))\)|\S+"; var result = Regex.Matches(line, pattern) .Cast() .SelectMany(x => x.Groups.Cast() .Where(m => !string.IsNullOrWhiteSpace(m.Value)) .Select(t => t.Value)) .ToList(); foreach (var s in result) Console.WriteLine(s); } }