From dee45ac231afd02797640cb335d86550aa620cbe Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Tue, 19 Dec 2023 12:59:43 +0900 Subject: [PATCH] [DOC] State MatchData#[] when multiple captures with the same name --- re.c | 11 +++++++++++ 1 file changed, 11 insertions(+) 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 = /(?.)(?.+)/.match("hoge") + * # => # + * m[:foo] #=> "oge" + * + * m = /\W(?.+)|\w(?.+)|(?.+)/.match("hoge") + * # + * m[:foo] #=> "oge" + * */ static VALUE