I'd like to apply a regexp code to the part of a string that is before and/or after a specific character, and that character must be outside parenthesis.
To be more specific, I am coding a website (in React.JS) showing logical calculation, and I want to remove the first and last parenthesis before and after the main logical operator. For example, in the string:
"((p∧r)∧(q∧r))∧(p∧q)"
I want to get only: "(p∧r)∧(q∧r)"
and "p∧q"
.
That means I want to get all the character before and after the only "∧"
outside of any parenthesis, and I want to remove the first opening parenthesis and the last closing parenthesis of the two string. (The result could be an array with the part before and after for example.)
I am already able to remove the first parenthis with this code :
str.replace(/(\()(.*)(\))/, "$2");
But that code is applied to the whole string right now.
So how do I apply this code to the two parts before and after the only "∧"
outside parenthesis ? If possible I'd prefer a code only in regexp, but a JavaScript part would do. Thanks by advance.