Thanks to Wiktor Stribiżew for answering my first question on extracting data from paired braces & pointing out the duplicate question : Regex to get string between curly braces
What I would like to do is also extract data from a string between arbitrary pairs of multicharacter delimiters, for example <= & =>. If there are multiple delimiters then I only want the data inside the inner most pair. I have tried varitions on the example Wiktor showed me but have only succeeded with single character delimiters, so trying again with my original lookbehind/lookahead solution, with the same problem - the lookahead correctly stops on the first match, the lookbehind only stops at the very first occurrence not the first match.
I have tried adding negative lookbehinds for additional braces & limiting the number of matches with {1} inside the lookbehind expression but neither of these work. I have found various comments on the difficulty of implementing lookbehind for regex & that not all regex implementations support all features - is there anyway to get the lookbehind to stop after the first match with C# (.Net) Regex.
The following code shows the regex I am using & what I am expecting & what I am getting.
var reg = new Regex(@"(?<=<=).*?(?==>)");
var matched = reg.Matches("I want to get <=data=> between paired <=<=<=delimiters=>=>=>=>");
foreach(var m in matched)
{
Console.WriteLine(m.ToString());
}
The result I expect is
data
delimiters
what I am getting is
data
<=<=delimiters