Method: Regexp#match?

Defined in:
re.c

#match?(string) ⇒ Boolean #match?(string, offset = 0) ⇒ Boolean

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.

/R.../.match?("Ruby")    # => true
/R.../.match?("Ruby", 1) # => false
/P.../.match?("Ruby")    # => false
$&                       # => nil

Overloads:

  • #match?(string) ⇒ Boolean

    Returns:

    • (Boolean)
  • #match?(string, offset = 0) ⇒ Boolean

    Returns:

    • (Boolean)


3851
3852
3853
3854
3855
3856
# File 're.c', line 3851

static VALUE
rb_reg_match_m_p(int argc, VALUE *argv, VALUE re)
{
    long pos = rb_check_arity(argc, 1, 2) > 1 ? NUM2LONG(argv[1]) : 0;
    return rb_reg_match_p(re, argv[0], pos);
}