Message 64950 - Python tracker
Huh. Maybe you're right. JavaScript, Ruby, and Perl all accept both regexes, although no two agree on what should be captured: js> "xyyzy".replace(/((x|y)*)*/, "($1, $2)") (xyy, y)zy js> "xyyzy".replace(/((x|y+)*)*/, "($1, $2)") (xyy, yy)zy >> "xyyzy".sub(/((x|y)*)*/, "(\\1, \\2)") => "(, y)zy" >> "xyyzy".sub(/((x|y+)*)*/, "(\\1, \\2)") => "(, yy)zy" DB<1> $_ = 'xyyzy'; s/((x|y)*)*/(\1 \2)/; print ( )zy DB<2> $_ = 'xyyzy'; s/((x|y+)*)*/(\1 \2)/; print ( yy)zy Ruby's behavior seems best to me.