[ python-Bugs-1284341 ] re nested conditional matching (?()) doesn't work
SourceForge.net
noreply at sourceforge.net
Thu Sep 8 00:36:08 CEST 2005
Bugs item #1284341, was opened at 2005-09-07 18:36
Message generated for change (Tracker Item Submitted) made by Item Submitter
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: Open
Resolution: None
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.
----------------------------------------------------------------------
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