The Simplest Expressions: Literal Strings
The simplest regular expressions are simply literal strings. There are plenty of times when itâs enough to search against a fixed search pattern. For example, you might test for the presence of the string âRubyâ:
sentence = "Ruby is the best Ruby-like programming language." sentence =~ /Ruby/ # => 2 - There are two instances of "Ruby".
Get Learning Rails now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.