Skip to content

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

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  # => "/"
See also #options #timeout #names #to_s also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0