regex help for a newbie

Marco Herrn herrn at gmx.net
Mon Apr 5 16:43:26 EDT 2004


On 2004-04-05, Diez B. Roggisch <deetsNOSPAM at web.de> wrote:
> def parse(input):
>     res = ""
>     level = 0
>     for c in input:
>         if c == "(":
>             level += 1
>         elif c == ")":
>             level -= 1
>         if level > 0 and c != "(":
>             res += c
>     return res

Thanks, that helped a lot. I had to rewrite it a bit, but now it works.
Many Thanks.
Marco


-- 
Marco Herrn             herrn at gmx.net
(GnuPG/PGP-signed and crypted mail preferred)
Key ID: 0x94620736




More information about the Python-list mailing list