summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2023-12-19 12:59:43 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2023-12-19 13:48:51 +0900
commitdee45ac231afd02797640cb335d86550aa620cbe (patch)
treefc1652c9a04f85e42d00517520e6eaca4dac924e
parentb5f33ba76f9657228746e079eafb8fa952a9ab8b (diff)
[DOC] State MatchData#[] when multiple captures with the same name
-rw-r--r--re.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/re.c b/re.c
index 352e5f0c73..f3be9a1fce 100644
--- a/re.c
+++ b/re.c
@@ -2151,6 +2151,17 @@ match_ary_aref(VALUE match, VALUE idx, VALUE result)
* m['foo'] # => "h"
* m[:bar] # => "ge"
*
+ * If multiple captures have the same name, returns the last matched
+ * substring.
+ *
+ * m = /(?<foo>.)(?<foo>.+)/.match("hoge")
+ * # => #<MatchData "hoge" foo:"h" foo:"oge">
+ * m[:foo] #=> "oge"
+ *
+ * m = /\W(?<foo>.+)|\w(?<foo>.+)|(?<foo>.+)/.match("hoge")
+ * #<MatchData "hoge" foo:nil foo:"oge" foo:nil>
+ * m[:foo] #=> "oge"
+ *
*/
static VALUE