End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
Regexp#~
~ rxp → integer or nil
re.c
View on GitHub ↗
VALUE
rb_reg_match2(VALUE re)
{
long start;
VALUE line = rb_lastline_get();
if (!RB_TYPE_P(line, T_STRING)) {
rb_backref_set(Qnil);
return Qnil;
}
start = rb_reg_search(re, line, 0, 0);
if (start < 0) {
return Qnil;
}
start = rb_str_sublen(line, start);
return LONG2FIX(start);
}
Match—Matches rxp against the contents of $_. Equivalent to <i>rxp</i> =~ $_.
Example
$_ = "input data" ~ /at/ #=> 7