新人学习正则表达式
想提举下面代码中的 id="14002"和
中国长江黄河这么2个值
我用(<tr\s*id="[0-9]*"|[^<>]+?(?=</div></td>))提取出来的时候包括了 发布时间 用户名 发布人等信息, 如何去掉这些不需要的内容
<table width="100%" cellpadding="0" cellspacing="0" border="1" style="border-bottom:#ffffff 1px solid;" bordercolordark="White" bordercolorlight="Black">
<tr height="25">
<td width="60%" style="border-bottom:#001177 1px solid;"><div align="center">
标题</div></td>
<td width="10%" style="border-bottom:#001177 1px solid;"><div align="center">发布时间</div></td>
<td width="10%" style="border-bottom:#001177 1px solid;"><div align="center">用户名</div></td>
<td width="10%" style="border-bottom:#001177 1px solid;"><div align="center">发布人IP</div></td>
<td width="10%" style="border-bottom:#001177 1px solid;"><div align="center">
操作</div></td>
</tr>
<tr id="14002" onmouseover="mouseover me" onmouseout="mouseout me" onclick="clickit me" language="vbscript" height="25">
<td align="center"><div align="left"><img src="images/gca.gif" WIDTH="11" HEIGHT="11">
中国长江黄河</div></td>
<td align="center">2007-1-7 15:09:31</td>
<td align="center">fadfac</td>
<td align="center">192.168.0.1</td>
<td align="center"><a href="news.aspx?id=14002" target="_blank">查看</a></td>
</tr>
想提举下面代码中的 id="14002"和
中国长江黄河这么2个值
我用(<tr\s*id="[0-9]*"|[^<>]+?(?=</div></td>))提取出来的时候包括了 发布时间 用户名 发布人等信息, 如何去掉这些不需要的内容
<table width="100%" cellpadding="0" cellspacing="0" border="1" style="border-bottom:#ffffff 1px solid;" bordercolordark="White" bordercolorlight="Black">
<tr height="25">
<td width="60%" style="border-bottom:#001177 1px solid;"><div align="center">
标题</div></td>
<td width="10%" style="border-bottom:#001177 1px solid;"><div align="center">发布时间</div></td>
<td width="10%" style="border-bottom:#001177 1px solid;"><div align="center">用户名</div></td>
<td width="10%" style="border-bottom:#001177 1px solid;"><div align="center">发布人IP</div></td>
<td width="10%" style="border-bottom:#001177 1px solid;"><div align="center">
操作</div></td>
</tr>
<tr id="14002" onmouseover="mouseover me" onmouseout="mouseout me" onclick="clickit me" language="vbscript" height="25">
<td align="center"><div align="left"><img src="images/gca.gif" WIDTH="11" HEIGHT="11">
中国长江黄河</div></td>
<td align="center">2007-1-7 15:09:31</td>
<td align="center">fadfac</td>
<td align="center">192.168.0.1</td>
<td align="center"><a href="news.aspx?id=14002" target="_blank">查看</a></td>
</tr>
解决方案 »
- 请教一个简单的问题
- 刚才 我去找了个空间,支持asp.net2.0和sql2005 我把东西传进去了 显示这个东西,有人碰到过吗
- 如何使一个下拉框变化带动另一个变化?
- 怎么在一已有的table中动态添加tr???解决问题百分相送.
- 用什么语句判断checkbox 已经被选中呢
- 在DataGrid中将数据库中自动增长的ID重新排序,却无法修改和删除?
- [求助]这里有大型虚拟主机商的代理吗?
- c#作的b/s项目,使用五笔输入法时的问题?
- ASP 留言板如何分行分段
- 在win2003下,为站点设置了SSL,为什么就不能访问了呢?
- 树状菜单的菜单名前能不能加一个checkbox框?
- Array.FindAll(numbers,delegate(int x)关于这句,请sp1234大哥或那位知道的来看下
<tr height=""25"">
<td width=""60%"" style=""border-bottom:#001177 1px solid;""><div align=""center"">
标题</div></td>
<td width=""10%"" style=""border-bottom:#001177 1px solid;""><div align=""center"">发布时间</div></td>
<td width=""10%"" style=""border-bottom:#001177 1px solid;""><div align=""center"">用户名</div></td>
<td width=""10%"" style=""border-bottom:#001177 1px solid;""><div align=""center"">发布人IP</div></td>
<td width=""10%"" style=""border-bottom:#001177 1px solid;""><div align=""center"">
操作</div></td>
</tr>
<tr id=""14002"" onmouseover=""mouseover me"" onmouseout=""mouseout me"" onclick=""clickit me"" language=""vbscript"" height=""25"">
<td align=""center""><div align=""left""><img src=""images/gca.gif"" WIDTH=""11"" HEIGHT=""11"">
中国长江黄河</div></td>
<td align=""center"">2007-1-7 15:09:31</td>
<td align=""center"">fadfac</td>
<td align=""center"">192.168.0.1</td>
<td align=""center""><a href=""news.aspx?id=14002"" target=""_blank"">查看</a></td>
</tr>";
Regex reg= new Regex(@"<tr\s*id=""([^""]*?)""[^>]*?>\s*<td[^>]*?>([\s\S]*?)</td>"); MatchCollection ms = reg.Matches(str);
if(ms.Count>0)
{
string sValue = ms[0].Result("$1");
Response.Write(sValue +"<BR>") ;
sValue = ms[0].Result("$2");
sValue = Regex.Replace(sValue,"<[^>]*?>","");
Response.Write(sValue);
}
MatchCollction mc = Regex.Matches(yourStr, "<tr\\s+(id=\".+?\").+?>\\s*<td.+?>\\s*<div.+?><img.+?>([\\s\\S]+?)</div>", RegexOptions.IgnoreCase);
foreach(Match m in mc)
{
m.Groups[1].Value;//id=
m.Groups[2].Value;//
}