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 nneonneo
Recipients BMintern, effbot, gerardjp, mchaput, nneonneo, timehorse
Date 2009-01-14.14:34:00
SpamBayes Score 0.004110973
Marked as misclassified No
Message-id <1231943643.23.0.579673348714.issue1519638@psf.upfronthosting.co.za>
In-reply-to
Content
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')
""
History
Date User Action Args
2009-01-14 14:34:03nneonneosetrecipients: + nneonneo, effbot, mchaput, timehorse, BMintern, gerardjp
2009-01-14 14:34:03nneonneosetmessageid: <1231943643.23.0.579673348714.issue1519638@psf.upfronthosting.co.za>
2009-01-14 14:34:02nneonneolinkissue1519638 messages
2009-01-14 14:34:00nneonneocreate