Project

General

Profile

Actions

Bug #17113

closed

/\K/ in separator for String#split behaves differently than /(?<=)/

Added by hanazuki (Kasumi Hanazuki) over 3 years ago. Updated over 3 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.8.0dev (2020-08-11T07:51:07Z master 5af983af4f) [x86_64-linux]
[ruby-core:99553]

Description

When a String is #splitted with a pattern containing /\K/ (lookbehind) operator,
the portion that matches the lookbehind pattern will not appear in the result.

"abcd".split(/b\Kc/)  # => ["a", "d"]
"abcd".split(/(?<=b)c/)  # => ["ab", "d"] -- expected result

In this example, since /b\Kc/ matches "c" in "abcd", the result is expected to be ["ab", "d"]. Actually ["a", "d"] is returned.
(?<=) operator seems to work expectedly.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0