Fetching the substring contained between two specific words

regex, ruby, ruby-on-rails-3, substring

Solution

Simple regular expression would do:

@var = "Hi, I want to extract container_start **ONLY THIS DYNAMIC CONTENT** container_end from the message contained between the container_start and container_end "
@var[/container_start(.*?)container_end/, 1] # => " **ONLY THIS DYNAMIC CONTENT** "

Problem

I wanted to know how to proceed when I am interested in the text contained between particular words using ruby. eg. ``` @var = "Hi, I want to extract container_start ONLY THIS DYNAMIC CONTENT container_end from the message contained between the container_start and container_end " ``` Now I want to extract the CAPITALIZED content from the string i.e. dynamic but always contained within the two containers (`container_start` and `container_end`)

Original source

Related problems