In PHP I can use a foreach loop such that I have access to both the key and value for example:
foreach($array as $key => $value)
I have the following code:
Regex regex = new Regex(pattern);
MatchCollection mc = regex.Matches(haystack);
for (int i = 0; i < mc.Count; i++)
{
GroupCollection gc = mc[i].Groups;
Dictionary<string, string> match = new Dictionary<string, string>();
for (int j = 0; j < gc.Count; j++)
{
//here
}
this.matches.Add(i, match);
}
at //here
I'd like to match.add(key, value)
but I cannot figure out how to get the key from the GroupCollection, which in this case should be the name of the capturing group. I know that gc["goupName"].Value
contains the value of the match.