fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5.  
  6. public class Test
  7. {
  8.  
  9. public static void Main()
  10. {
  11. 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)";
  12. var pattern = @"(?x)
  13. \s*\band\b\s* # whole word and enclosed with 0+ whitespaces
  14. (?= # start of a positive lookahead:
  15. (?:
  16. [^()]* # 0 or more chars other than ( and )
  17. \((?>[^()]+|(?<o>\()|(?<-o>\)))*(?(o)(?!))\) # a (...) substring with nested parens support
  18. )* # repeat the sequence of above two patterns 0 or more times
  19. [^()]*$ # 0 or more chars other than ( and ) and end of string
  20. ) # end of the positive lookahead";
  21. var results = Regex.Split(text, pattern);
  22. foreach (var s in results)
  23. Console.WriteLine(s);
  24. }
  25. }
Success #stdin #stdout 0.07s 21228KB
stdin
Standard input is empty
stdout
a > b
b = 0
(f = 1 and (g = 2 and j = 68) and v = 566)
a > b
b = 0
(f = 1 and g = 2)