Regex:
(?<1>[\d]+):{(?<2>\d+),(?<3>\d+),(?<4>\d+)}
For data:
411:{1,2,3},241:{4,1,2},314:{5,6,7}
will produce the following match/groups collections:
Match 0
Group 0: 411:{1,2,3}
Group 1: 411
Group 2: 1
Group 3: 2
Group 4: 3
Match 1
Group 0: 241:{4,1,2}
Group 1: 241
Group 2: 4
Group 3: 1
Group 4: 2
Match 2
Group 0: 314:{5,6,7}
Group 1: 314
Group 2: 5
Group 3: 6
Group 4: 7
You can use the following code:
string expression = "(?<1>[\d]*):{(?<2>\d),(?<3>\d),(?<4>\d)}";
string input = "411:{1,2,3},241:{4,1,2},314:{5,6,7}";
Regex re = new Regex(expression, RegexOptions.IgnoreCase);
MatchCollection matches = re.Matches(input);
for (int i = 0; i < matches.Count; i++)
{
Match m = matches[i];
// for i==0
// m.groups[0] == 411:{1,2,3}
// m.groups[1] == 411
// m.groups[2] == 1
// m.groups[3] == 2
// m.groups[4] == 4
}
Update
Having trouble getting it to work with pure regex and variable number of items in the list - maybe someone else can chime in here. A simple solution would be:
string expression = "(?<1>[\d]+):{(?<2>[\d,?]+)}";
string input = "411:{1,2,3,4,5},241:{4,1,234}";
Regex re = new Regex(expression, RegexOptions.IgnoreCase);
MatchCollection matches = re.Matches(input);
for (int i = 0; i < matches.Count; i++)
{
Match m = matches[i];
// for i==0
// m.groups[0] == "411:{1,2,3}"
// m.groups[1] == "411"
// m.groups[2] == "1,2,3"
int[] list = m.Groups[1].Split(",");
// now list is an array of what was between the curly braces for this match
}
Match list for above:
Match 0
Group 0: 411:{1,2,3,4,5}
Group 1: 411
Group 2: 1,2,3,4,5
Match 1
Group 0: 241:{4,1,234}
Group 1: 241
Group 2: 4,1,234