What would be the best way in Python to parse out chunks of text contained in matching brackets?
"{ { a } { b } { { { c } } } }"
should initially return:
[ "{ a } { b } { { { c } } }" ]
putting that as an input should return:
[ "a", "b", "{ { c } }" ]
which should return:
[ "{ c }" ] [ "c" ] []
Or this pyparsing version:
>>> from pyparsing import nestedExpr >>> txt = "{ { a } { b } { { { c } } } }" >>> >>> nestedExpr('{','}').parseString(txt).asList() [[['a'], ['b'], [[['c']]]]] >>>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With