I have the following regex:
@"{thing:(?:((\w)\2*)([^}]*?))+}"
I'm using it to find matches within a string:
MatchCollection matches = regex.Matches(string);
IEnumerable formatTokens = matches[0].Groups[3].Captures
.OfType<Capture>()
.Where(i => i.Length > 0)
.Select(i => i.Value)
.Concat(matches[0].Groups[1].Captures.OfType<Capture>().Select(i => i.Value));
This used to yield the results I wanted; however, my goal has since changed. This is the desired behavior now:
Suppose the string entered is 'stuff/{thing:aa/bb/cccc}{thing:cccc}'
I want formatTokens to be:
formatTokens[0] == "aa/bb/cccc"
formatTokens[1] == "cccc"
Right now, this is what I get:
formatTokens[0] == "/"
formatTokens[1] == "/"
formatTokens[2] == "cccc"
formatTokens[3] == "bb"
formatTokens[4] == "aa"
Note especially that "cccc" does not appear twice even though it was entered twice.
I think the problems are 1) the recapture in the regex and 2) the concat configuration (which is from when I wanted everything separated), but so far I haven't been able to find a combination that yields what I want. Can someone shed some light on the proper regex/concat combination to yield the desired results above?