I have these code lines for take to operators between parentheses:
string filtered = Regex.Replace(input, "\\(.*?\\)", string.Empty);
var result = filtered.Split(new[] { ' ' },
StringSplitOptions.RemoveEmptyEntries)
.Where(element => element == "OR" || element == "AND");
string temp = string.Join(" ", result);
These lines do not work for nested parentheses.
For example; it is working for this input :
X1 OR ( X2 AND X3 AND X4 AND X5 ) OR X6
It give me this result: OR OR
But, when my input has more than one nested parentheses, it works wrongly.
For this input:
X1 OR ( X2 AND( X3 AND X4 ) AND X5 ) OR X6
I want to take for result OR OR but it prints OR AND OR.
Although there are two (
characters in string, when it ends processing after matching the first )
character.
How can I adjust my regex pattern?