from pyparsing import nestedExpr
import sys
astring = sys.argv[1]
if not astring.startswith('('):
    astring = '(' + astring + ')'
expr = nestedExpr('(', ')')
result = expr.parseString(astring).asList()[0]
print(result)
How can a recursive regexp be implemented in python?