SRE does not always correctly handle groups in alternatives in repeats. For example: >>> re.match('((a)|b)*', 'abc').groups() ('b', '') Group 2 should obviously never be an empty string. As I understand it, the rule for groups inside a repeat is that they should have the last value they matched during the iterations of the repeat (or None if they never match), so in the above case Group 2 should be 'a'. To fix this, it appears that (when inside a repeat) the BRANCH opcode must call mark_save before trying an alternative and then call mark_restore if the alternative fails. The attached patch does this.
Logged In: YES user_id=7887 Good catch Greg! Just for reference, here are two tests to confirm that you're right: perl -e '"abc" =~ /^((a)|b)*/; print "$1 $2\n";' echo "abc"