/// <summary>
/// 正则表达式 抓取需要的内容
/// </summary>
/// <param name="HtmlCode">HTML代码</param>
/// <param name="RegexString">正则表达式</param>
/// <param name="GroupKey">关键字</param>
/// <returns></returns>
public static string[] GetRegValue(string HtmlCode, string RegexString, string GroupKey)
{
MatchCollection m;
Regex r;
r = new Regex(RegexString, RegexOptions.Multiline | RegexOptions.Singleline);
m = r.Matches(HtmlCode);
string[] MatchValue = new string[m.Count];
for (int i = 0; i < m.Count; i++)
{
MatchValue[i] = m[i].Groups[GroupKey].Value;
}
return MatchValue;
}


/// <summary>
/// 正则表达式 抓取需要的内容(从右向左匹配)
/// </summary>
/// <param name="HtmlCode">HTML代码</param>
/// <param name="RegexString">正则表达式</param>
/// <param name="GroupKey">关键字</param>
/// <returns></returns>
public static string[] GetRegValueByRight(string HtmlCode, string RegexString, string GroupKey)
{
MatchCollection m;
Regex r;
r = new Regex(RegexString,RegexOptions.RightToLeft| RegexOptions.Multiline | RegexOptions.Singleline);
m = r.Matches(HtmlCode);
string[] MatchValue = new string[m.Count];
for (int i = 0; i < m.Count; i++)
{
MatchValue[i] = m[i].Groups[GroupKey].Value;
}
return MatchValue;
}

相关文章:

  • 2022-12-23
  • 2021-10-19
  • 2022-12-23
  • 2022-12-23
  • 2021-11-22
  • 2022-12-23
  • 2021-06-03
  • 2021-10-19
猜你喜欢
  • 2021-07-24
  • 2022-12-23
  • 2022-12-23
  • 2021-05-21
  • 2021-08-15
  • 2022-12-23
相关资源
相似解决方案