I need to parse a string that contains some parentheses disposed recursively, but i'm having trouble with determining priority of parentheses. For exemple, I have the string
$truth = "((A^¬B)->C)";
and I need to return what is between the parentheses. I've already done it with the following regex:
preg_match_all("~\((.*?)\)~", $truth, $str);
But the problem is that it returns what is between the first "(" and the first ")", which is
(A^¬B
Instead of this, i need it to 'know' where the parentheses closes correctly, in order to return
(A^¬B)->C
How can I return this respecting the priority order? Thanks!