begin(p1)
public
Returns the offset of the start of the
nth element of the match array in the string. n can be a string or symbol to reference a named
capture.
m = /(.)(.)(\d+)(\d)/.match("THX1138.")
m.begin(0)
m.begin(2)
m = /(?<foo>.)(.)(?<bar>.)/.match("hoge")
p m.begin(:foo)
p m.begin(:bar)
Show source
static VALUE
match_begin(VALUE match, VALUE n)
{
int i = match_backref_number(match, n);
struct re_registers *regs = RMATCH_REGS(match);
match_check(match);
if (i < 0 || regs->num_regs <= i)
rb_raise(rb_eIndexError, "index %d out of matches", i);
if (BEG(i) < 0)
return Qnil;
update_char_offset(match);
return INT2FIX(RMATCH(match)->rmatch->char_offset[i].beg);
}