[issue2537] re.compile(r'((x|y+)*)*') should fail

Jason Orendorff report at bugs.python.org
Fri Apr 4 22:38:57 CEST 2008


Jason Orendorff <jason.orendorff at gmail.com> added the comment:

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.

__________________________________
Tracker <report at bugs.python.org>
<http://bugs.python.org/issue2537>
__________________________________


More information about the Python-bugs-list mailing list