substring and regular expression
Diez B.Roggisch
deets at web.de
Thu Aug 4 14:56:03 EDT 2005
borges2003xx <at> yahoo.it <borges2003xx <at> yahoo.it> writes:
>
> but in general is there a way to include in a re, in this example
> something like...matches iff p , and q in which p==q[::-1] ? A way to
> putting a small part of code of python in re? Thanx for your many helps
What you are after is a parser - there are plenty available. I prefer spark, but
pyparsing has gained lots of attention lately and is AFAIK the quasi-standard.
The problem you described is a classical instance of a so-called
context-free grammar.
There is absolutely _no_ way to teach regular expressions how to detect words
created based on a grammar of that kind. Really. It won't work.
So - either use a parser, or write a simple one yourself - the code above
qualifies as an attempt to do so.
Regards,
Diez
More information about the Python-list
mailing list