Python parsing bracketed blocks

后端 未结 9 1938
独厮守ぢ
独厮守ぢ 2020-11-27 04:44

What would be the best way in Python to parse out chunks of text contained in matching brackets?

\"{ { a } { b } { { { c } } } }\"

should i

9条回答
  •  余生分开走
    2020-11-27 05:17

    Or this pyparsing version:

    >>> from pyparsing import nestedExpr
    >>> txt = "{ { a } { b } { { { c } } } }"
    >>>
    >>> nestedExpr('{','}').parseString(txt).asList()
    [[['a'], ['b'], [[['c']]]]]
    >>>
    

提交回复
热议问题