re = /^How to.*optional\):$/im
str = '//Text comes before this..
How to care for Split Leaf Plant
The Split leaf philodendron, also called monstera deliciosa or swiss cheese plant, is a large, popular, easy- care houseplant that is not really in the philodendron family. There is a great deal of confusion about what to call this plant; the various names have become inter-changeable over the years.
Here is more info (optional):
//And more text goes here'
# Print the match result
str.scan(re) do |match|
puts match.to_s
end
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Ruby, please visit: http://ruby-doc.org/core-2.2.0/Regexp.html