I am trying to use regular expressions in a ruby on rails app to search through a given string and find any instances of opening and closing square brackets, (ie [ and ]) and select the contents between the two.
For example:
Lorem ipsum [dolor sit] amet...
In this string the result would be: [dolor sit]
I played around with rubular a bit and found that this more or less does what I want
/\[.*?\]/
So my question is, how do i match everything within the two square brackets without selecting the brackets themselves? And also how do I actually integrate them into a ruby script?
Regular expressions are totally new ground for me so any help you guys can offer would be much appreciated 🙂
Collecting multiple captures of a regexp is a job for String#scan