Sample text:
heading1
foo=bar
baz=qux
heading2
spam=ham
heading3
this=that
I want the text from heading1 to heading2 (excluding).
So I tried a non-greedy match from "heading1" to "\n\n", but it is still greedy and overmatches:
var result = Regex.Match(text, "heading1\n(.*)\n{2}?", RegexOptions.Singleline)
.Groups[1]
.Value;
(I already have a solution by searching between "heading1" and "heading2", but I prefer to use the above approach as a learning exercise for non-greedy matching.)
UPDATE:
My question is simpler, has source text, is for C# specifically. It's easier to understand the problem. The linked question is technically relevant, but harder to apply to this case.