Skip to content

End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

Regexp#===

rxp === str → true or false

Case Equality—Used in case statements.

Example
a = "HELLO"
case a
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"

Following a regular expression literal with the === operator allows you to compare against a String.

Example
/^[a-z]*$/ === "HELLO" #=> false
/^[A-Z]*$/ === "HELLO" #=> true
See also #== #=~ .union #~ also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.0