如何验证表达式“([A] and [B]) or ([C] and [D])” 符合bool表达式规
如何验证表达式“([A] and [B]) or ([C] and [D])” 符合bool表达式规则 1:使用[A],[B],[C]....[Z]代表一个bool值。 2:左右括号要匹配 3:([A] and [B]) or ([C] and [D]) 等价于 (true & true) || (true $ false) 4:表达式长度不限
使用JS验证
慕容708150
浏览 572回答 2
2回答
守候你守候我
function isVailed(a) { var patrn=/^\s*\(\s*(true)|(false)\s+(and)\s+(true)|(false)\s*\)\s*(or)\s*\(\s*(true)|(false)\s+(and)\s+(true)|(false)\s*\)\s*$/; if (!patrn.exec(a)) return false;else return true; } 对多余的空格会自动处理,只要调用这个方法 例如 isVailed(" (true and false) or (false and false) ")就可以验证