正则问题。。。。。。。。。。。。 急````
Html为 :
<a href=\ "/Expert/TopicView2.asp?id=1232562\ " target=\ "_blank\ "> 1 </a> <a href=\ "/Expert/TopicView2.asp?id=2532363\ " target=\ "_blank\ "> 2 </a> <a href=\ "/Expert/TopicView2.asp?id=2345264\ " target=\ "_blank\ "> 33 </a> <a href=\ "/Expert/TopicView2.asp?id=433265\ " target=\ "_blank\ "> 4444 </a>
这样的。
我用正则这样取id=多少,不知道为什么老是取不到,帮看下下面那错了!! 谢了。
MatchCollection mc = Regex.Matches(Html, " <a href=\ "/Expert/TopicView2.asp?id=(? <url> [A-Za-z0-9_-]*?)\ " target=\ "_blank\ "> ", RegexOptions.IgnoreCase);
foreach (Match m in mc)
{
Response.Write(m.Groups[ "url "].Value + " <br> ");
Response.Flush();
}
------解决方案--------------------在楼主的基础上改造了下
string Html = " <a href=\ "/Expert/TopicView2.asp?id=1232562\ " target=\ "_blank\ "> 1 </a> <a href=\ "/Expert/TopicView2.asp?id=2532363\ " target=\ "_blank\ "> 2 </a> <a href=\ "/Expert/TopicView2.asp?id=2345264\ " target=\ "_blank\ "> 33 </a> <a href=\ "/Expert/TopicView2.asp?id=433265\ " target=\ "_blank\ "> 4444 </a> ";
MatchCollection mc = Regex.Matches(Html, " <a\\s+href=\ "/Expert/TopicView2\\.asp\\?id=(? <url> [^\ "]*?)\ "[^> ]*?> ", RegexOptions.IgnoreCase);
foreach (Match m in mc)
{
Response.Write(m.Groups[ "url "].Value + " <br> ");
Response.Flush();
}