kukko kukko - 2 months ago 6x
PHP Question

Regular expression match multiple substring

I have written a regular expression to test how a string is a logical expression or not. Here is the regular expression:


And here is the subject which I tested with the expression above:


function in PHP return the following array:


I got a wrong logical operator because it's not match only the
pattern but also match the
operator. How should I rewrite the regular expression to not match multiple strings in the brackets?


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:


With <=>, use


or, better yet in some cases,