Well, as soon as you give up the idea that parsing nested expressions should work at unlimited depth, you can simply use regular expressions, specifying the maximum depth in advance. Here's how:
def nested_matcher (n):
This will lead to the conclusion
['a', '(b[c]d)', 'e'] ['a', '[b[c]d]', 'e'] ['[hello [world]]', ' abc ', '[123]', ' ', '[xyz jkl]']
source share