Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
Regexp#source
() -> ::String
source → string
re.c
View on GitHub ↗
static VALUE
rb_reg_source(VALUE re)
{
VALUE str;
rb_reg_check(re);
str = rb_str_dup(RREGEXP_SRC(re));
return str;
}
Returns the original string of self:
Example
/ab+c/ix.source # => "ab+c"
Regexp escape sequences are retained:
Example
/\x20\+/.source # => "\\x20\\+"
Lexer escape characters are not retained:
Example
/\//.source # => "/"