This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: re nested conditional matching (?()) doesn't work
Type: Stage:
Components: Regular Expressions Versions: Python 2.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: niemeyer Nosy List: edemaine, georg.brandl, niemeyer
Priority: normal Keywords:

Created on 2005-09-07 22:36 by edemaine, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (3)
msg26244 - (view) Author: Erik Demaine (edemaine) Date: 2005-09-07 22:36
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.
msg26245 - (view) Author: Erik Demaine (edemaine) Date: 2005-09-07 23:09
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.
msg26246 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2005-09-14 17:32
Logged In: YES 
user_id=1188172

The fix is already in Python 2.4 CVS, so I'm closing as Fixed.
History
Date User Action Args
2022-04-11 14:56:12adminsetgithub: 42352
2005-09-07 22:36:08edemainecreate