[前][次][番号順一覧][スレッド一覧]

ruby-changes:73434

From: Nobuyoshi <ko1@a...>
Date: Mon, 5 Sep 2022 19:36:45 +0900 (JST)
Subject: [ruby-changes:73434] a8a7c9d05d (master): [DOC] [Bug #17120] Fix match-reset `\K`

https://git.ruby-lang.org/ruby.git/commit/?id=a8a7c9d05d

From a8a7c9d05d2f9a4f49b43a42d8430faa37c4a4c6 Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Mon, 5 Sep 2022 18:21:29 +0900
Subject: [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, <i>anchoring</i> the match to a specific position. https://github.com/ruby/ruby/blob/trunk/doc/regexp.rdoc#L550
 * <tt>(?<!</tt><i>pat</i><tt>)</tt> - <i>Negative lookbehind</i>
   assertion: ensures that the preceding characters do not match
   <i>pat</i>, but doesn't include those characters in the matched text
-* <tt>\K</tt> - Uses an positive lookbehind of the content preceding
-  <tt>\K</tt> in the regexp.  For example, the following two regexps are
-  almost equivalent:
 
-      /ab\Kc/
-      /(?<=ab)c/
+* <tt>\K</tt> - <i>Match reset</i>: the matched content preceding
+  <tt>\K</tt> 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 <i>$&</i> equals <tt>"c"</tt>, while the
+  matched position is different.
 
   As are the following two regexps:
 
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]