Bug #1312
closedString#rindex(Regexp, offset) doesn't seem to match greedily
Description
=begin
I may be wrong but I was expecting:
"abcdefg ".rindex(/\w+/,10)
to return 0.
This is what actually happens:
irb(main):003:0> "abcdefg ".rindex(/\w+/,10)
=> 6
irb(main):004:0> $~
=> #<MatchData "g">
irb(main):005:0> $~[0]
=> "g"
irb(main):006:0> $~.offset(0)
=> [6, 7]
The Regexp seems to match in a non-greedy way. The /\w+/ only matches the "g". I was expecting it to be greedy and match "abcdefg" and return 0 instead of 6.
Please correct me if I'm wrong in my expectation.
Thank you,
David
=end
Updated by nobu (Nobuyoshi Nakada) about 16 years ago
=begin
Hi,
At Tue, 24 Mar 2009 15:16:12 +0900,
David Ellis wrote in [ruby-core:23009]:
I may be wrong but I was expecting:
"abcdefg ".rindex(/\w+/,10)
to return 0.
Wrong expectation.
String#rindex returns the rightmost position can match.
--
Nobu Nakada
=end