From: kasumi@... Date: 2020-08-13T07:21:15+00:00 Subject: [ruby-core:99576] [Ruby master Bug#17118] String#index and #rindex return wrong result for Regexp patterns containing /\K/ Issue #17118 has been reported by hanazuki (Kasumi Hanazuki). ---------------------------------------- Bug #17118: String#index and #rindex return wrong result for Regexp patterns containing /\K/ https://bugs.ruby-lang.org/issues/17118 * Author: hanazuki (Kasumi Hanazuki) * Status: Open * Priority: Normal * ruby -v: ruby 2.8.0dev (2020-08-13T01:14:20Z master 69b5241c36) [x86_64-linux] * Backport: 2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN ---------------------------------------- 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. ```ruby # expected -- index of "c" is returned "abcdbce".index(/b\Kc/) # => 2 "abcdbce".rindex(/b\Kc/) # => 5 ``` ```ruby # actual -- index of "b" is returned "abcdbce".index(/b\Kc/) # => 1 "abcdbce".rindex(/b\Kc/) # => 4 ``` -- https://bugs.ruby-lang.org/ Unsubscribe: