A Regexp holds a regular expression, used to match a pattern against strings. Regexps are created using the /…/ literals, and by the Regexp::new constructor. Regular expressions (regexps) are patterns which describe the contents of a string. They’re used for testing whether a string contains a given pattern, or extracting the portions that string. They are created with the /pat/ literals or the Regexp.new constructor. If a string contains the pattern, it is said to 'match'. A literal string matches itself.

Examples: /hay/ =~ 'haystack' #=> 0 /y/.match('haystack') #=> #<MatchData “y”> /needle/.match('haystack') #=> nil /hay/.match('haystack') #=> #<MatchData “hay”>