///
/// 正则表达式 抓取需要的内容
///
/// HTML代码
/// 正则表达式
/// 关键字
///
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;
}
///
/// 正则表达式 抓取需要的内容(从右向左匹配)
///
/// HTML代码
/// 正则表达式
/// 关键字
///
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;
}
|