I wanted to apply the regular expressions to find and replace the unwanted parenthesis and operators in the input string.
Here is the possible input for me: 4 types from a through d. [Invalid Inputs]
a). 1 and (2 or 3) ()
b). ( and 2)
c). (or 4)
d). ()
all these 4 are invalid cases , the valid ones should be as [Valid Inputs]
a). 1 and 2
b). (1 and 2)
c). 1 and (2 or 4)
Based on this requirement, i have written the regex, but i have written in 2 parts and need help in joining them to a single regex.
a). ([(]+[\s]*[)]+) -> to find the empty parenthesis
b). (([(]+[\s]*[and|or]+[\s]*)) -> to find cases like b or c in invalid inputs.
Kindly suggest a way to combine the above. further i want to do removal of the invalid parts in the inputs, which i can do in javascript like string.replace(regex).
Kindly analyze and give comments on this process.
is a Regex that checks for the content of a bracket pair: either empty, missing operand on the left, missing operand on the right or no operands at all.
But watch out! This neither checks for validity of un-bracketed expressions, nor is it rekursive, as Colin Fine already mentioned. If you liked to check for that, I’d propose to replace from inside up: