首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

去除table,tr,td属性的正则表达式

2012-01-14 
求一个去除table,tr,td属性的正则表达式先看代码:HTML codetable border0 bgcolor#0033cc cellspac

求一个去除table,tr,td属性的正则表达式
先看代码:

HTML code
<table border="0" bgcolor="#0033cc" cellspacing="1" cellpadding="0" width="500" align="center"><tr bgcolor="#ffffff"> <td align="center" height="18">这里是内容</td></tr></table>

我要问的问题是:
用正则表达式匹配.然后变成如下:
HTML code
<table><tr> <td>这里是内容</td></tr></table>

如何写这个正则? 谢谢!!

[解决办法]
C# code
using System;using System.Text.RegularExpressions;class Program{  static void Main()  {    string s0 = @"<table border=""0"" bgcolor=""#0033cc"" cellspacing=""1"" cellpadding=""0"" width=""500"" align=""center""><tr bgcolor=""#ffffff""> <td align=""center"" height=""18""><a href=""."">这里是内容</a></td></tr></table>";    string s1 = Regex.Replace(s0, @"(?i)<(table|tr|td)(?:\s+(?:""[^""]*""|'[^']*'|[^""'>])*)?>", "<$1>");    Console.WriteLine(s1);  }}/* 程序输出:<table><tr> <td><a href=".">这里是内容</a></td></tr></table>*/ 

热点排行