/* * call-seq: * mtch.select([index]*) => array * * Uses each <i>index</i> to access the matching values, returning an * array of the corresponding matches. * * m = /(.)(.)(\d+)(\d)/.match("THX1138: The Movie") * m.to_a #=> ["HX1138", "H", "X", "113", "8"] * m.select(0, 2, -2) #=> ["HX1138", "X", "113"] */ static VALUE match_select(argc, argv, match) int argc; VALUE *argv; VALUE match; { if (argc > 0) { rb_raise(rb_eArgError, "wrong number of arguments (%d for 0)", argc); } else { struct re_registers *regs = RMATCH(match)->regs; VALUE target = RMATCH(match)->str; VALUE result = rb_ary_new(); int i; int taint = OBJ_TAINTED(match); for (i=0; i<regs->num_regs; i++) { VALUE str = rb_str_substr(target, regs->beg[i], regs->end[i]-regs->beg[i]); if (taint) OBJ_TAINT(str); if (RTEST(rb_yield(str))) { rb_ary_push(result, str); } } return result; } }