instance method
MatchData#regexp
() -> ::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));
RB_OBJ_WRITE(match, &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/