You have to use captures if you have repeated groups.
Match m = Regex.Match("class A { B(){} C(){} }", @"class (?<class>\w+) (?<b>\{)(?:\s*(?<method>\w+)\(\)\{\})*\s*(?<-b>\})");
var methods = m.Groups["method"].Captures;
for (int i = 0; i < methods.Count; i++)
Console.WriteLine(methods[i].Value);
Output:
B
C
Additionally: You cannot use -b
as group name, change it to b_end
or similar, otherwise you will not capture b
and -b
groups.
class (?<class>\w+) (?<b_start>\{)(?:\s*(?<method>\w+)\(\)\{\})*\s*(?<b_end>\})