I am trying to use regular expressions in ruby on a rails application to search on a given string and search for any instances of opening and closing square brackets (ie [and]) and select the contents between them.
For instance:
Lorem ipsum [dolor sit] amet...
On this line, the result will be: [dolor sit]
I played with the ruble a bit and found that it more or less does what I want
/\[.*?\]/
So my question is: how do I match everything in square brackets without choosing the brackets themselves? And also how can I integrate them into a ruby script?
Regular expressions are a whole new foundation for me, so any help you guys can offer will be greatly appreciated :)
source
share