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.

Author ezio.melotti
Recipients ezio.melotti, terry.reedy
Date 2011-09-29.01:04:45
SpamBayes Score 5.551115e-17
Marked as misclassified No
Message-id <>
The problem is in Lib/idlelib/
m = prog.match(chars, col)
if not prog:
    return False
new = m.expand(self.replvar.get())

prog = re.compile('foo')  # i.e. text in the find box
chars = '>>> "foo"\n'  # i.e. the text in the IDLE window
col = 5
self.replvar.get() = 'bar\'  # i.e. the var with the trailing \

m.expand() searches for groups to expand, like \1 and \2 to refer to the first and second matching group, and fails with:

Traceback (most recent call last):
  File "/home/wolf/dev/py/py3k/Lib/", line 194, in __next
    c = self.string[self.index + 1]
IndexError: string index out of range

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/wolf/dev/py/py3k/Lib/", line 278, in _expand
    template = sre_parse.parse_template(template, pattern)
  File "/home/wolf/dev/py/py3k/Lib/", line 729, in parse_template
    this = sget()
  File "/home/wolf/dev/py/py3k/Lib/", line 210, in get
  File "/home/wolf/dev/py/py3k/Lib/", line 196, in __next
    raise error("bogus escape (end of line)")
sre_constants.error: bogus escape (end of line)

Using things like foo\5bar also results in a crash because the group \5 is not found.

I'm not sure what the expected behavior should be.  If numeric/named backreferences are not supposed to be supported, I guess a re.escape() might solve the problem.  If they are supported the last line should be wrapped in a try/except that looks for sre_constants.error errors and possibly IndexErrors too (this might actually be fixed in

BTW, I think that "if not prog" in the snippet I pasted should be "if not m".  Pattern objects are always True (I assume prog is always a pattern object).

Do you want to work on a patch?
Date User Action Args
2011-09-29 01:04:47ezio.melottisetrecipients: + ezio.melotti, terry.reedy
2011-09-29 01:04:47ezio.melottisetmessageid: <>
2011-09-29 01:04:46ezio.melottilinkissue13052 messages
2011-09-29 01:04:45ezio.melotticreate