Skip to content

Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →

instance method

Regexp#===

regexp === string → true or false

Returns true if self finds a match in string:

Example
/^[a-z]*$/ === 'HELLO' # => false
/^[A-Z]*$/ === 'HELLO' # => true

This method is called in case statements:

Example
s = 'HELLO'
case s
when /\A[a-z]*\z/; print "Lower case\n"
when /\A[A-Z]*\z/; print "Upper case\n"
else               print "Mixed case\n"
end # => "Upper case"
See also #== #=~ .union #~ also in 4.1 · 4.0 · 3.4 · 3.2 · 3.1 · 3.0