Skip to content
instance method

Regexp#match?

(::interned str, ?::int offset) -> bool
(nil, ?::int offset) -> false
match?(string) → true or false
match?(string, offset = 0) → true or false

Returns true or false to indicate whether the regexp is matched or not without updating $~ and other related variables. If the second parameter is present, it specifies the position in the string to begin the search.

Example
/R.../.match?("Ruby")    # => true
/R.../.match?("Ruby", 1) # => false
/P.../.match?("Ruby")    # => false
$&                       # => nil
See also #match #named_captures #inspect #names also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0