#region 匹配字符/获取信息
/// <summary>
/// 匹配字符/获取信息
/// </summary>
/// <param name="NowHTML_text">被匹配字符串</param>
/// <param name="MatchName">匹配内容</param>
/// <returns>匹配到的信息</returns>
public static string MatchFunction(string NowHTML_text, string MatchName)
{
string Values = string.Empty;
try
{
MatchCollection objMatchs = Regex.Matches(NowHTML_text, MatchName, RegexOptions.None);
int results = objMatchs.Count;
if (results > 0)
{
Values = objMatchs[0].Groups[1].Value;
}
}
catch
{ }
return Values;
}
#endregion
使用例子:
var txtsearch ="http://detail.tmall.com/item.htm?id=12281501775&cm_cat=50016756";
var id = MatchFunction(txtsearch,"&id=(.+?)&"); //截取id
那么截取得到的字符串就是12281501775