using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; public class Test { public static void Main() { var text = "a > b and b = 0 and (f = 1 and (g = 2 and j = 68) and v = 566) and a > b and b = 0 and (f = 1 and g = 2)"; var pattern = @"(?x) \s*\band\b\s* # whole word and enclosed with 0+ whitespaces (?= # start of a positive lookahead: (?: [^()]* # 0 or more chars other than ( and ) \((?>[^()]+|(?\()|(?<-o>\)))*(?(o)(?!))\) # a (...) substring with nested parens support )* # repeat the sequence of above two patterns 0 or more times [^()]*$ # 0 or more chars other than ( and ) and end of string ) # end of the positive lookahead"; var results = Regex.Split(text, pattern); foreach (var s in results) Console.WriteLine(s); } }