正则表达式不是正确的工具。手动扫描字符串。
伪代码:
depth = 0for character in some_string: depth += character == '(' depth -= character == ')' if depth < 0: breakif depth != 0: print "unmatched parentheses"
正则表达式不是正确的工具。手动扫描字符串。
伪代码:
depth = 0for character in some_string: depth += character == '(' depth -= character == ')' if depth < 0: breakif depth != 0: print "unmatched parentheses"