using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { public class Program { public static void Main(string[] args) { Regex r = new Regex( @"^([01A-Z](?![01A-Z])| (?[|&>=]\((?!,))| (?,(?!\)))| (?\))| (?~\((?!\)))| (?\)))+ (?(dyadic)(?!))(?(comma)(?!))(?(monadic)(?!))$" , RegexOptions.IgnorePatternWhitespace); string target = @"&(A,|(B,C)"; string[] passList = { @"&(A,B)", @"~(0)", @"&(A,~(B))", @">(~(=(D,A)),~(B))", @"=(A,&(C,D))", @"T"}; for(int i = 0; i(~(=(D,A),~(B))", @">", @">(,)", @"|(,A)", @"|(A,)", @"~()", @"DF", @"~(DS)", @"=(AD,BC)" }; for(int i = 0; i