Project

General

Profile

Actions

Bug #1312

closed

String#rindex(Regexp, offset) doesn't seem to match greedily

Bug #1312: String#rindex(Regexp, offset) doesn't seem to match greedily

Added by davidkellis (David Ellis) over 16 years ago. Updated over 14 years ago.

Status:
Rejected
Assignee:
-
Target version:
-
ruby -v:
ruby 1.9.1p0 (2009-01-30 revision 21907) [i386-darwin9.6.0]
Backport:
[ruby-core:23009]

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

Actions

Also available in: PDF Atom