/// <summary> /// 匹配单项 /// </summary> /// <param name="input">字符串</param> /// <param name="pattern">要匹配的正则表达式模式</param> /// <param name="ro">枚举值的一个按位组合,默认值为指定不区分大小写的匹配</param> /// <returns></returns> public static RegexDictionary Match(this string input, string pattern, RegexOptions ro = RegexOptions.IgnoreCase) { RegexDictionary dic = new RegexDictionary(); Match m = Regex.Match(input, pattern, ro); if (!m.Success) { return(dic); } for (int i = 0; i < m.Groups.Count; i++) { dic[i] = m.Groups[i].Value; } return(dic); }
/// <summary> /// 匹配多项 /// </summary> /// <param name="input">字符串</param> /// <param name="pattern">要匹配的正则表达式模式</param> /// <param name="ro">枚举值的一个按位组合,默认值为指定不区分大小写的匹配</param> /// <returns></returns> public static ListDictionary Matches(this string input, string pattern, RegexOptions ro = RegexOptions.IgnoreCase) { ListDictionary list = new ListDictionary(); MatchCollection mc = Regex.Matches(input, pattern, ro); if (mc.Count == 0) { return(list); } for (int j = 0; j < mc.Count; j++) { RegexDictionary dic = new RegexDictionary(); Match m = mc[j]; for (int i = 0; i < m.Groups.Count; i++) { dic[i] = m.Groups[i].Value; } list[j] = dic; } return(list); }