I have two groups of text:
firstgroup
(some content)
endgroup
secondgroup
(some content)
endgroup
I’m trying to just capture the first group (not the second group). I’m using this regular expression:
firstgroup(.|\n)*endgroup
For some reason, that regular expressions selects both first group and second group (probably because it looks at the very last “endgroup” above). Is there a way to modify my regex such that I only select the first group (and not the second group)?
You need a lazy quantifier
to end the group as soon as possible. See http://www.rubular.com/r/D6UkOnMYLj.
(And you could use the
/mflag to make the.match new lines.)