End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
String#match?
match?(pattern, offset = 0) → true or false
string.c
View on GitHub ↗
static VALUE
rb_str_match_m_p(int argc, VALUE *argv, VALUE str)
{
VALUE re;
rb_check_arity(argc, 1, 2);
re = get_pat(argv[0]);
return rb_reg_match_p(re, str, argc > 1 ? NUM2LONG(argv[1]) : 0);
}
Returns true or false based on whether a match is found for self and pattern.
Note: does not update Special global variables at Regexp.
Computes regexp by converting pattern (if not already a Regexp).
Example
regexp = Regexp.new(pattern)
Returns true if self+.match(regexp) returns a MatchData object, false otherwise:
Example
'foo'.match?(/o/) # => true 'foo'.match?('o') # => true 'foo'.match?(/x/) # => false
If Integer argument offset is given, the search begins at index offset:
Example
'foo'.match?('f', 1) # => false 'foo'.match?('o', 1) # => true