Give name to group.
start1(?<val>.*?)end1|start2(?<val>.*?)end2
And get value as:
mt.Groups["val"].Value
The original problem is that without names the group between start1
and end1
has index 1
, and group between start2
and end2
has index 2
, as you can see from the following picture:
Or another solution is to use regex like:
(?<=start([12])).*?(?=end\1)
And then in your code:
Console.WriteLine(mt.Value);
will display the required content.