Parsing nested constructs

David wizzardx at gmail.com
Sat Sep 8 17:25:17 EDT 2007


On 9/8/07, tool69 <kib2 at free.fr> wrote:
> Hi,
>
> I need to parse some source with nested parenthesis, like this :
>

If this is exactly how your data looks, then how about a loop which
searches for "{item" and the following "}"? You can use the "find"
string method for that.

Otherwise, if the items don't look exactly like "{item", but the
formatting is otherwise exactly the same as above, then look for lines
that have both "{" and "}" on them, then get the string between them.

Otherwise, if { and } and the item aren't always on the same line,
then go through the string character by character, keep track of when
you encounter "{" and "}". When you encounter a "}" and there was a
"{" before (ie, not a "}"), then get the string between the "{" and
the "}"



More information about the Python-list mailing list