I'm trying to match all text in the block:
group :development do
gem 'test'
end
In the context above, I want to return "gem 'test'"
.
What I'm using is:
/(?<=group :development do)(.*)(?=end)/m
Why doesn't it work?
I'm trying to match all text in the block:
group :development do
gem 'test'
end
In the context above, I want to return "gem 'test'"
.
What I'm using is:
/(?<=group :development do)(.*)(?=end)/m
Why doesn't it work?
I'm not exactly sure why, but changing the .*
to .*?
allows this to match.
Rubular: http://www.rubular.com/r/GaQj6cM0rk
It seems like it should match fine with .*
as well, but for some reason it doesn't appear to be backtracking.
Here is the Rubular when .*
is used instead: http://www.rubular.com/r/jKf0bDZi7T
Note that regardless of the reason for this behavior, you should be using .*?
anyway, otherwise you would only find a single match from the beginning of the first block to the end of the last block (if there were multiple blocks in a string).