c# regex match string code example

Example 1: c# regex match

var regex = new Regex(@"(?<=%download%#)\d+");
return regex.Matches(strInput);

Example 2: c# regex

public static Dictionary<string, string> FindPattern(this string text, string pattern)
{
    Regex expression = new Regex(pattern);
    Match match = expression.Match(text);
    Dictionary<string, string> matchvalue = new Dictionary<string, string>();
    if (match.Success)
    {
        foreach (string g in expression.GetGroupNames())
        {
            matchvalue[g] = match.Groups[g].Value;
        }
        return matchvalue;
    }
    else
    {
        foreach (string g in expression.GetGroupNames())
        {
            matchvalue[g] = "";
        }
    }
    return matchvalue;
}