Problems with re
Berthold Höllmann
bhoel at server.python.net
Fri May 21 06:24:56 EDT 1999
I have a regular expression wich, im most cases does what I want it to
do. But at least on one string it get's into an endless loop (OK I din't
wait forever). See the attaced example:
Python 1.5.2 (#2, Apr 22 1999, 14:34:42) [GCC egcs-2.91.66 19990314
(egcs-1.1.2 on linux2
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> import re
>>> RE = re.escape
>>> CP = r'\CallPython'
>>> loopR = re.compile(
... "(?:" + RE(CP) + r'(\[.*\])?{(?P<CodeC>(?:' + '""".*?"""|".*?"'
+ "|'''.*?'''|'.*?'|" +
... '{.*?}+?|[^{]+?)+?))}',
... re.MULTILINE|re.DOTALL)
>>>
>>> LL = loopR.match("\CallPython{LaTeXPy.PyLaTeX(dir(math))}")
>>> LL = loopR.match("\CallPython{LaTeXPy.PyLaTeX({1:1,2:2,3:3}")
>>> LL = loopR.match("\CallPython{LaTeXPy.PyLaTeX(dir(math)); LaTeXPy.PyLaTeX({1:1,2:2,3:3}")
I try to parse a LaTeX file for the included "\CallPython" statements to
extract python commands from this statement.
Do you have any idea?
Thanks
Berthold
--
bhoel at starship.python.net
It is unlawful to use this email address for unsolicited ads
(USC Title 47 Sec.227). I will assess a US$500 charge for
reviewing and deleting each unsolicited ad.
More information about the Python-list
mailing list