regex help for a newbie

Marco Herrn herrn at gmx.net
Tue Apr 6 16:23:16 EDT 2004


On 2004-04-06, marco <marco at reimeika.ca> wrote:
> Marco Herrn <herrn at gmx.net> writes:
>> the parts in a recursive function. So the thing I want to achieve here
>> is to extract %(BBB%(CCC)BBB) and %(DDD).
>
> p1, p2 = "aaa%(BBB%(CCC)BBB)aaa%(DDD)aaa".split("aaa")[1:-1]

Doesn't help, since I do not know that there is the string "aaa". It was
just an example. I do not know any of the strings/characters. The only
thing I know is that a percent sign indicates that the content inside
the following parentheses is an expression that has to be evaluated.

I need to do this by real parsing. In fact the solution from Diez isn't
enough. I will have to write a much more flexible parser, as I realized.

Diez mentioned spark as a parser. I also found yappy, which is a parser
generator. I have not much experience with parsers. What is the
difference between these two? When should one use the one, when the
other?

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