Skip to content
instance method

String#match?

(::Regexp | ::string pattern, ?::int offset) -> bool
match?(pattern, offset = 0) → true or false

Returns whether a match is found for self and the given arguments; does not update Regexp Global Variables.

Computes regexp by converting pattern (if not already a Regexp):

Example
regexp = Regexp.new(pattern)

Returns true if self[offset..].match(regexp) returns a MatchData object, false otherwise:

Example
'foo'.match?(/o/) # => true
'foo'.match?('o') # => true
'foo'.match?(/x/) # => false
'foo'.match?('f', 1) # => false
'foo'.match?('o', 1) # => true

Related: see Querying.

See also #match #next #lstrip! #next! also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0