From: "Benjamin J. Tilly" Date: 2001-05-30T00:47:56+09:00 Subject: [ruby-talk:15939] Re: Regexp (a\1) matz@zetabits.com (Yukihiro Matsumoto) wrote: >Hi, > >In message "[ruby-talk:15924] Re: Regexp (a\1)" > on 01/05/29, ts writes: > >|Y> * backreferences corresponding to unclosed/unmatched parentheses >|Y> should fail always. >| >| This is not what do perl, and this will be a difference from perl/ruby. >| >| For perl a reference exist only *after* it has found the close ')' >| ruby .... *when* ...... open '(' > >Hmm, I don't get the point. The following 2-line program is valid in both Ruby and Perl. But it gives different results: print "OK\n" if "ababba" =~ /^(a|(b\1))*$/; print "Not OK\n" if "ababbba" =~ /^(a|(b\1))*$/; In Perl \1 matches the previous iteration through the group. >| This mean that perl can re-use a previous backreference, for example this >| is valid in perl >| >| "aaaaaa" =~ /^(a\1?)(a\1?)(a\2?)(a\3?)$/ >| >| and it must give the result $1 = "a", $2 = "aa", $3 = "a", $4 = "aa" (this >| is extract from the tests of perl). > >Ruby gives same result (before and after the modification). >Probably I'm missing something. The example that I gave should give you different results before and after your modification. Neither will be what Perl gives. Cheers, Ben