[ python-Bugs-1284341 ] re nested conditional matching (?()) doesn't work
SourceForge.net
noreply at sourceforge.net
Wed Sep 14 19:32:35 CEST 2005
Bugs item #1284341, was opened at 2005-09-08 00:36
Message generated for change (Comment added) made by birkenfeld
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1284341&group_id=5470
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Regular Expressions
Group: Python 2.4
>Status: Closed
>Resolution: Fixed
Priority: 5
Submitted By: Erik Demaine (edemaine)
Assigned to: Gustavo Niemeyer (niemeyer)
Summary: re nested conditional matching (?()) doesn't work
Initial Comment:
Here is a simple regular expression that should match
\o, \{o}, {\o}, and \{o}}: (This example arose as
a simplification of a general accent matcher for
LaTeX/BibTeX.)
r = re.compile(r'(\{)?\"(\{)?(.)(?(2)\})(?(1)\})')
However, it fails on two out of four of the desired
matches:
r.search(r'\o) ## returns None (WRONG)
r.search(r\{o}').group() ## returns '\"{o}"' (CORRECT)
r.search(r'{\o).group() ## returns \"o} (WRONG)
r.search(r{\{o}}').group() ## returns '{\"{o}}'
(CORRECT)
The third case is particularly bizarre. Incidentally,
the behavior is different if '(.)' is replaced by '.'
(incorrect in different ways).
I have tested this on Python 2.4.1 on Windows and a CVS
version on Linux. I do not believe it is a platform issue.
----------------------------------------------------------------------
>Comment By: Reinhold Birkenfeld (birkenfeld)
Date: 2005-09-14 19:32
Message:
Logged In: YES
user_id=1188172
The fix is already in Python 2.4 CVS, so I'm closing as Fixed.
----------------------------------------------------------------------
Comment By: Erik Demaine (edemaine)
Date: 2005-09-08 01:09
Message:
Logged In: YES
user_id=265183
Whoops, I just updated CVS to the latest HEAD and discovered
that the problem has already been solved. Nice work! Sorry
about the extraneous report, but let me turn this into a
request that the fix go into 2.4.2, not just 2.5.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1284341&group_id=5470
More information about the Python-bugs-list
mailing list