I am trying to create a Regex expression to validate logical &&
||
string combonation and its corresponding opening and closing ()>
I think the reason you are not able to validate expressions without a wrapping ()
is the wrapping parentheses in your core nesting logic. If you take out the following parentheses I note below, then the other two non-wrapped expressions validate:
^(?=^[^()]*\((?>[^()]+|\((?)|\)(?<-DEPTH>))*(?(DEPTH)(?!))\)[^()]*$...
^^ remove this remove this ^^
Then in order to allow expressions that are not just numerical, you need to replace your restrictive \d
with a more liberal definition of what you want to validate, say, [0-9a-zA-Z]
:
...[(]*\d+[)]*(\s+(&&|\|\|)\s+[(]*\d+[)]*)*$
^^ change these expression ^^
So it would become:
...[(]*[0-9a-zA-Z]+[)]*(\s+(&&|\|\|)\s+[(]*[0-9a-zA-Z]+[)]*)*$
Demo: http://ideone.com/jwkcpL