fork(18) download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text.RegularExpressions;
  4.  
  5. public class Test
  6. {
  7. public static void Main()
  8. {
  9. string hieroglyphics = @"^(?=^[^()]*(?>[^()]+|\((?<DEPTH>)|\)(?<-DEPTH>))*(?(DEPTH)(?!))[^()]*$)[(]*[0-9a-zA-Z]+[)]*(\s+(&&|\|\|)\s+[(]*[0-9a-zA-Z]+[)]*)*$";
  10.  
  11.  
  12. var tests = new List<string>
  13. {
  14. // Working
  15. "(1 && 2)",
  16. "((1 && 2) && (3 || 4))",
  17.  
  18. // Not working
  19. "1 && 2",
  20. "(1 && 2) && (3 || 4)",
  21. "Stack && Overflow"
  22. };
  23.  
  24. foreach (var test in tests)
  25. Console.WriteLine(test + ": " + Regex.IsMatch(test, hieroglyphics));
  26. }
  27. }
Success #stdin #stdout 0.09s 34256KB
stdin
Standard input is empty
stdout
(1 && 2): True
((1 && 2) && (3 || 4)): True
1 && 2: True
(1 && 2) && (3 || 4): True
Stack && Overflow: True