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 gerardjp
Recipients BMintern, effbot, gerardjp, mchaput, nneonneo
Date 2008-07-11.08:17:19
SpamBayes Score 0.07437274
Marked as misclassified No
Message-id <>
Hi All,

I found a workaround for the re.sub method so it does not raise an
exception but returns and empty string when backref-ing an empty group.

This is the nutshell:

When doing a search and replace with sub, replace the group represented
as optional for a group represented as an alternation with one empty
subexpression. So instead of this “(.+?)?” use this “(|.+?)” (without
the double quotes).

If there’s nothing matched by this group the empty subexpression
matches. Then an empty string is returned instead of a None and the sub
method is executed normally instead of raising the “unmatched group” error.

A complete description is in my post:


Date User Action Args
2008-07-11 08:17:21gerardjpsetspambayes_score: 0.0743727 -> 0.07437274
recipients: + gerardjp, effbot, mchaput, nneonneo, BMintern
2008-07-11 08:17:20gerardjpsetspambayes_score: 0.0743727 -> 0.0743727
messageid: <>
2008-07-11 08:17:20gerardjplinkissue1519638 messages
2008-07-11 08:17:19gerardjpcreate