Rindex with regexp

Using rindex with a regexp would appear to undermine greediness.

irb(main):012:0> "a--b--c".rindex(/[-]+/)
=> 5
irb(main):013:0> p $~.begin(0)
5
=> nil
irb(main):014:0> p $~.end(0)
6
=> nil

I would expect the 5 to be a 4.

T.

Hi,

···

In message "Re: rindex with regexp" on Tue, 28 Dec 2004 13:09:58 +0900, "trans. (T. Onoma)" <transami@runbox.com> writes:

Using rindex with a regexp would appear to undermine greediness.

irb(main):012:0> "a--b--c".rindex(/[-]+/)
=> 5
irb(main):013:0> p $~.begin(0)
5

I would expect the 5 to be a 4.

rindex is as lazy as me not to seek longest match.

              matz.

lol :slight_smile:

T.

P.S. BTW, I recently saw a picture of you. A Most Excellent Beard!

···

On Monday 27 December 2004 11:22 pm, Yukihiro Matsumoto wrote:

rindex is as lazy as me not to seek longest match.

       matz.