At the moment I work with some logical and mathematical expressions given as a String. Unfortunately, there is a need to use brackets on expressions when using chars: '&' and '|' (used instead of '||').
Valid expressions:
(x + 2) & (y * 4) | (i - 4)
(5 > 4) | (6y + 4)
Invalid expressions:
x + 2 & y * 4 | i - 4
5 > 4 | 6y + 4
I have tried to check String with RegEx, something like:
[)][ \t\n\r]*[&][ \t\n\r]*[(]
makes sense.
The problem is: how to find all '&' and '|' chars and find presence of near brackets?
Edit: I have a solution based on searching for index of those characters, then going in both ways and looking for brackets. Maybe I can make it in more simple way with RegEx?