110,536
社区成员
发帖
与我相关
我的任务
分享
<tr bgcolor="#FFFF99" onmouseover="this.bgColor='#FFCCCC'" onmouseout="this.bgColor='#FFFF99'">
<td width="108" height="25">
<a href="/url.htm?u=http://www.123.com/" target="_blank">测试测试</a>
</td>
<td width="108">
121.12.105.213
</td>
<td width="180">
2009年 5月3日 晚上11点59分
</td>
<td width="84" align="center">
测试测试
</td>
<td>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<a href="/url.htm?u=http://www.123.com/" target="_blank">测试测试</a>
</td>
</tr>
</table>
</td>
<td width="108">
测试测试
</td>
<td width="68" align="center">
<a href="/url.htm?u=http://www.123.com/" target="_blank">点击查看</a>
</td>
</tr>
using (StreamWriter sw = new StreamWriter(@"G:\正则学习\test.txt", true, Encoding.Default))
{
for (int i = 0; i < 1100; i++)
{
sw.WriteLine(yourStr);
sw.WriteLine(DateTime.Now.ToString());
sw.WriteLine();
}
}
Stopwatch sWatch = new Stopwatch();
sWatch.Start();
Regex reg = new Regex(@"<tr(?>(?:(?!onmouseover).)*)onmouseover=""(?>[^""]*)""(?>(?:(?!onmouseout).)*)onmouseout=""(?>[^""]*)""[^>]*>(?>(?:<tr(?>[^>]*)>(?<o>)|</tr>(?<-o>)|(?!</?tr).)*)(?(o)(?!))</tr>", RegexOptions.IgnoreCase | RegexOptions.Compiled | RegexOptions.Singleline);
string src = string.Empty;
using (StreamReader sr = new StreamReader(@"G:\正则学习\test.txt", Encoding.Default))
{
src = sr.ReadToEnd();
}
using (StreamWriter sw = new StreamWriter(@"G:\正则学习\result.txt", true, Encoding.Default))
{
MatchCollection mc = reg.Matches(src);
foreach (Match m in mc)
{
sw.WriteLine(m.Value);
}
}
sWatch.Stop();
richTextBox2.Text += "Done...\n";
richTextBox2.Text += sWatch.ElapsedMilliseconds.ToString() + " ms";
@"<tr[^>]*onmouseover=""[^""]*""[^>]*onmouseout=""[^""]*""[^>]*>.*</tr>"
//str为你的html
foreach (Match match in Regex.Matches(str, @"<tr.*?onmouseover=""this.bgColor='#FFCCCC'"" onmouseout=""this.bgColor='#FFFF99'""[^>]*>((?><tr[^>]*>(?<o>)|</tr>(?<-o>)|[\s\S])*)(?(o)(?!))</tr>"))
{
Console.WriteLine(match.Value);
}