Skip to content

End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

Regexp#options

options → integer

Returns an integer whose bits show the options set in self.

The option bits are:

Example
Regexp::IGNORECASE # => 1
Regexp::EXTENDED   # => 2
Regexp::MULTILINE  # => 4

Examples:

Example
/foo/.options    # => 0
/foo/i.options   # => 1
/foo/x.options   # => 2
/foo/m.options   # => 4
/foo/mix.options # => 7

Note that additional bits may be set in the returned integer; these are maintained internally internally in self, are ignored if passed to Regexp.new, and may be ignored by the caller:

Returns the set of bits corresponding to the options used when creating this regexp (see Regexp::new for details). Note that additional bits may be set in the returned options: these are used internally by the regular expression code. These extra bits are ignored if the options are passed to Regexp::new:

Example
r = /\xa1\xa2/e                 # => /\xa1\xa2/
r.source                        # => "\\xa1\\xa2"
r.options                       # => 16
Regexp.new(r.source, r.options) # => /\xa1\xa2/
See also #names #source #named_captures #timeout also in 4.1 · 4.0 · 3.4 · 3.3 · 3.1 · 3.0