I\'m failing to match a nested capturing group multiple times, the result only gives me the last inner capture instead.
Input string: =F2=0B=E2some te
You just need to access the match.Groups[2].Captures
collection.
See the regex demo
What you need is a CaptureCollection. See this Regex.Match reference:
Captures
Gets a collection of all the captures matched by the capturing group, in innermost-leftmost-first order (or innermost-rightmost-first order if the regular expression is modified with theRegexOptions.RightToLeft
option). The collection may have zero or more items.(Inherited from Group.)
Here is a sample demo that outputs all the captures from Groups[2]
CaptureCollection (F2
, 0B
, E2
, C2
, A3
):
var pattern = "(=([0-9A-F]{2}))+";
var result = Regex.Matches("=F2=0B=E2some text =C2=A3", pattern)
.Cast<Match>().Select(p => p.Groups[2].Captures)
.ToList();
foreach (var coll in result)
foreach (var v in coll)
Console.WriteLine(v);