offset(p1)
public
Returns a two-element array containing the beginning and ending offsets of
the nth match.
m = /(.)(.)(\d+)(\d)/.match("THX1138.")
m.offset(0)
m.offset(4)
Show source
/*
* call-seq:
* mtch.offset(n) => array
*
* Returns a two-element array containing the beginning and ending offsets of
* the <em>n</em>th match.
*
* m = /(.)(.)(\d+)(\d)/.match("THX1138.")
* m.offset(0)
* m.offset(4)
*/
static VALUE
match_offset(match, n)
VALUE match, n;
{
int i = NUM2INT(n);
if (i < 0 || RMATCH(match)->regs->num_regs <= i)
rb_raise(rb_eIndexError, "index %d out of matches", i);
if (RMATCH(match)->regs->beg[i] < 0)
return rb_assoc_new(Qnil, Qnil);
return rb_assoc_new(INT2FIX(RMATCH(match)->regs->beg[i]),
INT2FIX(RMATCH(match)->regs->end[i]));
}