From a8a7c9d05d2f9a4f49b43a42d8430faa37c4a4c6 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Mon, 5 Sep 2022 18:21:29 +0900 Subject: [PATCH] [DOC] [Bug #17120] Fix match-reset `\K` --- doc/regexp.rdoc | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/doc/regexp.rdoc b/doc/regexp.rdoc index f3844d5729..a7e2a0786e 100644 --- a/doc/regexp.rdoc +++ b/doc/regexp.rdoc @@ -550,12 +550,16 @@ characters, anchoring the match to a specific position. * (?pat) - Negative lookbehind assertion: ensures that the preceding characters do not match pat, but doesn't include those characters in the matched text -* \K - Uses an positive lookbehind of the content preceding - \K in the regexp. For example, the following two regexps are - almost equivalent: - /ab\Kc/ - /(?<=ab)c/ +* \K - Match reset: the matched content preceding + \K in the regexp is excluded from the result. For example, + the following two regexps are almost equivalent: + + /ab\Kc/ =~ "abc" #=> 0 + /(?<=ab)c/ =~ "abc" #=> 2 + + These match same string and $& equals "c", while the + matched position is different. As are the following two regexps: