Strings

Strings in Ruby are specified the same way as they are in Python. A string is enclosed by either single or double quotes.

puts "my string"

Regular expressions are defined in the Regexp class. The =~ operator can be used to search a regular expression in a string. The operator matches the regex against the string, and returns the character index of the starting character in the regular expression.

pattern = /orange/
string = "I eat lots of oranges"

puts pattern =~ string

>>14