I have written a regular expression to test how a string is a logical expression or not. Here is the regular expression:
You should exclude
<>! before the operator and
= after operator. Then, just to shorten, group the operators tighter.
You could also shorten it a bit with this:
or, better yet in some cases,