MatchCollection mc = Regex.Matches(Search_Html_DanPin, @"(class=(pic)).*?(product_id=(\d+))"); //Search_Html_DanPin 是我获取的HEML页面内容 //class=(pic)).*?(product_id=(\d+) 写的不对 请教此处应该怎么写 string[] res = new string[mc.Count]; for (int i = 0; i < res.Length; i++) { res[i] = ""; } for (int i = 0; i < mc.Count; i++) { res[i] = mc[i].Value.ToString(); } return res;
MatchCollection mc = Regex.Matches(Search_Html_DanPin, @"(?is)<a[^>]*?class="pic"[^>]*?href="[^"]*?product_id=([^"#]*?)(?=#)"); 报错 语法错误?
act=click&pos=229230" href="http://product.dangdang.com/product.aspx?product_id=22923011#ddclick?
act=click&pos=229" class="pic"等等,这些都是同一个东西。而你的所谓正则,并不懂语法分析,只懂简单匹配词法。
http://www.cnblogs.com/insus/archive/2012/10/30/2745843.html
取Group[1].Value
//Search_Html_DanPin 是我获取的HEML页面内容
//class=(pic)).*?(product_id=(\d+) 写的不对 请教此处应该怎么写
string[] res = new string[mc.Count];
for (int i = 0; i < res.Length; i++)
{
res[i] = "";
}
for (int i = 0; i < mc.Count; i++)
{
res[i] = mc[i].Value.ToString();
}
return res;
报错 语法错误?