End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
MatchData#regexp
regexp → regexp
re.c
View on GitHub ↗
static VALUE
match_regexp(VALUE match)
{
VALUE regexp;
match_check(match);
regexp = RMATCH(match)->regexp;
if (NIL_P(regexp)) {
VALUE str = rb_reg_nth_match(0, match);
regexp = rb_reg_regcomp(rb_reg_quote(str));
RMATCH(match)->regexp = regexp;
}
return regexp;
}
Returns the regexp that produced the match:
Example
m = /a.*b/.match("abc") # => #<MatchData "ab"> m.regexp # => /a.*b/