/// <summary>
/// Regex 抓取需要的內容
/// </summary>
/// <param name="HtmlCode">HTML代碼</param>
/// <param name="RegexString">Regex</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>
/// Regex 抓取需要的內容(從右向左匹配)
/// </summary>
/// <param name="HtmlCode">HTML代碼</param>
/// <param name="RegexString">Regex</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;
}