62,074
社区成员
发帖
与我相关
我的任务
分享
<p class="t">xxxxx</p><font>xxxxxxx</font><br/><br/>
<span>xxxxxxxx</span ><br/> <br/>
<span>xxxx</span ><br/><br/>
<p class="t">xxxxx</p> - <a herf="xxxxxx.html">xxxxxxxx</a><br/><br/>
<span>xxxxxx</span ><br/><br/>
<p class="t">xxxxxx</p> - <a herf="xxxxxx.html">xxxx</a><br/><br/>
<div><p class="t">xxxxx</p></div><br/><br/>
<p class="t">xxxxxxx</p> - <a herf="xxxxx.html">xxxxxxxxxxxx</a><br/><br/>
<table><tr><td>xxxxxx</td></tr></table><br/><br/>
string regex = "<p class=\"t\">(?<content1>.+?)</p>\\s[-]\\s<a href=(?<url>.+?)>(? <content2>.+?)</a>";
Regex reg = new Regex(regex , RegexOptions.IgnoreCase | RegexOptions.Compiled);
MatchCollection ms = reg.Matches(myHtml);
foreach (Match m in ms) { string url = m.Groups["url"].Value;
string content1 = m.Groups["content1"].Value;
string content2 = m.Groups["content2"].Value;
}
string regex = @"(?i)<p\s*class=""t"">(?<content1>.*?)</p>\s*(?:-)\s*<a\s*href=""(?<url>[^""]+?)"">(?<content2>.+?)</a>";
string myHtml = @"<p class=""t"">xxxxx</p><font>xxxxxxx</font>
<span>xxxxxxxx</span >
<span>xxxx</span >
<p class=""t"">xxxxx</p> - <a href=""xxxxxx.html"">xxxxxxxx</a>
<span>xxxxxx</span >
<p class=""t"">xxxxxx</p> - <a href=""xxxxxx.html"">xxxx</a>
<div><p class=""t"">xxxxx</p></div>
<p class=""t"">xxxxxxx</p> - <a href=""xxxxx.html"">xxxxxxxxxxxx</a>
<table><tr><td>xxxxxx</td></tr></table>";
Regex reg = new Regex(regex);
MatchCollection ms = reg.Matches(myHtml);
foreach (Match m in ms)
{
Console.WriteLine(m.Value);
Console.WriteLine(m.Groups["url"].Value);
Console.WriteLine(m.Groups["content1"].Value);
Console.WriteLine(m.Groups["content2"].Value);
Console.WriteLine("-------------------------------");
}
string regex = "(?i)<p\s*class=\"t\">(?<content1>.*?)</p>\s*(?:-)\s*<a\s*href=\"(?<url>[^"]+?)\">(?<content2>.+?)</a>";
Regex reg = new Regex(regex , RegexOptions.IgnoreCase | RegexOptions.Compiled);
MatchCollection ms = reg.Matches(myHtml);
foreach (Match m in ms) { string url = m.Groups["url"].Value;
string content1 = m.Groups["content1"].Value;
string content2 = m.Groups["content2"].Value;
}