c# regex match capture part code example

Example: c# regex get capture value

public static List<Dictionary<string, List<string>>> FindMultiMatchPatterns(this string text, string pattern)
        {
            List<Dictionary<string, List<string>>> matchvalues = new List<Dictionary<string, List<string>>>();

            Regex expression = new Regex(pattern);
            Match match = expression.Match(text);
            while (match.Success)
            {
                Dictionary<string, List<string>> matchvalue = new Dictionary<string, List<string>>();
                foreach (string g in expression.GetGroupNames())
                {
                    matchvalue[g] = new List<string>();
                    foreach (var c in match.Groups[g].Captures)
                    {
                        matchvalue[g].Add(c.ToString());
                    }
                }
                matchvalues.Add(matchvalue);
                match = match.NextMatch();
            }
            return matchvalues;
        }