diff --git a/re.c b/re.c index 36bc026d34..391ec876cf 100644 --- a/re.c +++ b/re.c @@ -1356,6 +1356,7 @@ match_end(VALUE match, VALUE n) * returns the matched substring for the given name: * * m = /(?.)(.)(?.+)/.match("hoge") + * # => # * m.match('foo') # => "h" * m.match(:bar) # => "ge" * @@ -2124,29 +2125,29 @@ match_ary_aref(VALUE match, VALUE idx, VALUE result) /* * call-seq: - * mtch[i] -> str or nil - * mtch[start, length] -> array - * mtch[range] -> array - * mtch[name] -> str or nil + * matchdata[index] -> string or nil + * matchdata[start, length] -> array + * matchdata[range] -> array + * matchdata[name] -> string or nil * - * Match Reference -- MatchData acts as an array, and may be accessed - * using the normal array indexing techniques. mtch[0] - * is equivalent to the special variable $&, and returns - * the entire matched string. mtch[1], - * mtch[2], and so on return the values of the matched - * backreferences (portions of the pattern between parentheses). + * When arguments +index+, +start and +length+, or +range+ are given, + * returns match and captures in the style of Array#[]: * - * m = /(.)(.)(\d+)(\d)/.match("THX1138.") - * m #=> # - * m[0] #=> "HX1138" - * m[1, 2] #=> ["H", "X"] - * m[1..3] #=> ["H", "X", "113"] - * m[-3, 2] #=> ["X", "113"] + * m = /(.)(.)(\d+)(\d)/.match("THX1138.") + * # => # + * m[0] # => "HX1138" + * m[1, 2] # => ["H", "X"] + * m[1..3] # => ["H", "X", "113"] + * m[-3, 2] # => ["X", "113"] + * + * When string or symbol argument +name+ is given, + * returns the matched substring for the given name: + * + * m = /(?.)(.)(?.+)/.match("hoge") + * # => # + * m['foo'] # => "h" + * m[:bar] # => "ge" * - * m = /(?a+)b/.match("ccaaab") - * m #=> # - * m["foo"] #=> "aaa" - * m[:foo] #=> "aaa" */ static VALUE @@ -2194,20 +2195,28 @@ match_aref(int argc, VALUE *argv, VALUE match) /* * call-seq: + * values_at(*indexes) -> array * - * mtch.values_at(index, ...) -> array + * Returns match and captures at the given +indexes+, + * which may include any mixture of: * - * Uses each index to access the matching values, returning an array of - * the corresponding matches. + * - Integers. + * - Ranges. + * - Names (strings and symbols). * - * m = /(.)(.)(\d+)(\d)/.match("THX1138: The Movie") - * m.to_a #=> ["HX1138", "H", "X", "113", "8"] - * m.values_at(0, 2, -2) #=> ["HX1138", "X", "113"] - * m.values_at(1..2, -1) #=> ["H", "X", "8"] * - * m = /(?\d+) *(?[+\-*\/]) *(?\d+)/.match("1 + 2") - * m.to_a #=> ["1 + 2", "1", "+", "2"] - * m.values_at(:a, :b, :op) #=> ["1", "2", "+"] + * Examples: + * + * m = /(.)(.)(\d+)(\d)/.match("THX1138: The Movie") + * # => # + * m.values_at(0, 2, -2) #=> ["HX1138", "X", "113"] + * m.values_at(1..2, -1) #=> ["H", "X", "8"] + * + * m = /(?\d+) *(?[+\-*\/]) *(?\d+)/.match("1 + 2") + * # => # + * m.values_at(0, 1..2, :a, :b, :op) + * # => ["1 + 2", "1", "+", "1", "2", "+"] + * */ static VALUE