fork(1) download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text.RegularExpressions;
  5.  
  6. namespace Rextester
  7. {
  8. public class Program
  9. {
  10. public static void Main(string[] args)
  11. {
  12. Regex r = new Regex(
  13. @"^([01A-Z](?![01A-Z])|
  14. (?<dyadic>[|&>=]\((?!,))|
  15. (?<comma-dyadic>,(?!\)))|
  16. (?<dBracket-comma>\))|
  17. (?<monadic>~\((?!\)))|
  18. (?<uBracket-monadic>\)))+
  19. (?(dyadic)(?!))(?(comma)(?!))(?(monadic)(?!))$"
  20. , RegexOptions.IgnorePatternWhitespace);
  21. string target = @"&(A,|(B,C)";
  22. string[] passList = {
  23. @"&(A,B)",
  24. @"~(0)",
  25. @"&(A,~(B))",
  26. @">(~(=(D,A)),~(B))",
  27. @"=(A,&(C,D))",
  28. @"T"};
  29. for(int i = 0; i<passList.Length; i++){
  30. if (r.Match(passList[i]).Success)
  31. {
  32. Console.WriteLine("String: " + passList[i] + " Matches.");
  33. }
  34. else{
  35. Console.WriteLine("Match expected for"+ passList[i] + " but failed");
  36. }
  37. }
  38.  
  39. string[] failList = {
  40. @"&(A,B",
  41. @"~(A,B)",
  42. @"&(A,|(B))",
  43. @">(~(=(D,A),~(B))",
  44. @">",
  45. @">(,)",
  46. @"|(,A)",
  47. @"|(A,)",
  48. @"~()",
  49. @"DF",
  50. @"~(DS)",
  51. @"=(AD,BC)"
  52. };
  53.  
  54. for(int i = 0; i<failList.Length; i++){
  55. if (r.Match(failList[i]).Success)
  56. {
  57. Console.WriteLine("String: " + failList[i] + " matches but should not.");
  58. }
  59. else{
  60. Console.WriteLine("No match as expected");
  61. }
  62. }
  63. }
  64. }
  65. }
Success #stdin #stdout 0.03s 134720KB
stdin
Standard input is empty
stdout
String: &(A,B) Matches.
String: ~(0) Matches.
String: &(A,~(B)) Matches.
String: >(~(=(D,A)),~(B)) Matches.
String: =(A,&(C,D)) Matches.
String: T Matches.
No match as expected
No match as expected
No match as expected
No match as expected
No match as expected
No match as expected
No match as expected
No match as expected
No match as expected
No match as expected
No match as expected
No match as expected