/* * call-seq: * mtch[i] => obj * mtch[start, length] => array * mtch[range] => array * * Match Reference---<code>MatchData</code> acts as an array, and may be * accessed using the normal array indexing techniques. <i>mtch</i>[0] is * equivalent to the special variable <code>$&</code>, and returns the entire * matched string. <i>mtch</i>[1], <i>mtch</i>[2], and so on return the values * of the matched backreferences (portions of the pattern between parentheses). * * m = /(.)(.)(\d+)(\d)/.match("THX1138.") * m[0] #=> "HX1138" * m[1, 2] #=> ["H", "X"] * m[1..3] #=> ["H", "X", "113"] * m[-3, 2] #=> ["X", "113"] */ static VALUE match_aref(argc, argv, match) int argc; VALUE *argv; VALUE match; { VALUE idx, rest; rb_scan_args(argc, argv, "11", &idx, &rest); if (!NIL_P(rest) || !FIXNUM_P(idx) || FIX2INT(idx) < 0) { return rb_ary_aref(argc, argv, match_to_a(match)); } return rb_reg_nth_match(FIX2INT(idx), match); }