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>\)))*(?(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);
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uQ29sbGVjdGlvbnMuR2VuZXJpYzsKdXNpbmcgU3lzdGVtLkxpbnE7CnVzaW5nIFN5c3RlbS5UZXh0LlJlZ3VsYXJFeHByZXNzaW9uczsKCnB1YmxpYyBjbGFzcyBUZXN0CnsKCQoJcHVibGljIHN0YXRpYyB2b2lkIE1haW4oKQoJewoJCXZhciB0ZXh0ID0gImEgPiBiIGFuZCBiID0gMCBhbmQgKGYgPSAxIGFuZCAoZyA9IDIgYW5kIGogPSA2OCkgYW5kIHYgPSA1NjYpIGFuZCBhID4gYiBhbmQgYiA9IDAgYW5kIChmID0gMSBhbmQgZyA9IDIpIjsKCQl2YXIgcGF0dGVybiA9IEAiKD94KQpccypcYmFuZFxiXHMqICMgd2hvbGUgd29yZCBhbmQgZW5jbG9zZWQgd2l0aCAwKyB3aGl0ZXNwYWNlcwooPz0gICAgICAgICAgICMgc3RhcnQgb2YgYSBwb3NpdGl2ZSBsb29rYWhlYWQ6ICAgCiAgKD86IAogICAgW14oKV0qICAgICMgMCBvciBtb3JlIGNoYXJzIG90aGVyIHRoYW4gKCBhbmQgKQogICAgXCgoPz5bXigpXSt8KD88bz5cKCl8KD88LW8+XCkpKSooPyhvKSg/ISkpXCkgICMgYSAo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