Bobby Xiao <nneon...@gmail.com> added the comment: Well, in this example the group (ar) is unmatched, so sre throws the error, and because of the alternation, the workaround you mentioned doesn't seem to directly apply.
A better example is probably re.sub("foo(?:b(ar)|foo)","\\1","foofoo") because this can't be simply repaired by refactoring the regex. The correct behaviour, as I have observed in other regex implementations, is to replace the group by the empty string; for example, in Javascript: >>> 'foobar'.replace(/foo(?:b(ar)|baz)/,'$1') "ar" >>> 'foobaz'.replace(/foo(?:b(ar)|baz)/,'$1') "" ---------- versions: +Python 2.5, Python 2.6, Python 3.0 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue1519638> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com