Actions
Bug #17118
closedString#index and #rindex return wrong result for Regexp patterns containing /\K/
Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.8.0dev (2020-08-13T01:14:20Z master 69b5241c36) [x86_64-linux]
Description
When the pattern Regexp given to String#index
and String#rindex
contain a /\K/
(lookbehind) operator, these methods return the position where the beginning of the lookbehind pattern matches, while they are expected to return the position where the \K
matches.
# expected -- index of "c" is returned
"abcdbce".index(/b\Kc/) # => 2
"abcdbce".rindex(/b\Kc/) # => 5
# actual -- index of "b" is returned
"abcdbce".index(/b\Kc/) # => 1
"abcdbce".rindex(/b\Kc/) # => 4
Actions
Like0
Like0Like0