You cannot determine if a string with arbitrary number of parentheses is actually syntactically correct (i.e. every parenthesis is closed) using regular expressions because it's fundamentally more complex (you need a stack-based solution to solve a context-free grammar class problem) than what a regular expression can handle (a simple DFA).
So you need to reconsider how you're approaching this problem.
That said, here's a small program that checks if the expression has balanced number of parentheses and then evaluates the result.
def is_correct_expression(expr: str) -> bool:
pars = []
try:
for c in expr:
if c == '(':
pars.append(c)
if c == ')':
pars.pop()
return True
except IndexError:
return False
if __name__ == '__main__':
expr = '((30 >=50) and (20 <= 100)) or (52 > 35)'
if is_correct_expression(expr):
result = eval(expr)
print(result)
else:
print('invalid expression')
output:
True