急求:正则过滤WORD转换成的HTML的标签
用户发新闻时经常粘贴word里的东西,HTML代码见最下面
新闻列表页要取这样的内容的前200个字,如何过滤.从网上搜的只能过滤一般的html标签,不能过滤如
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office " /> 这样的,
截取前200个字符时可能会形成断位,如下也要过滤掉
<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office
这会导致新闻列表页表格混乱等.时间急,请大师们帮忙!
<P class=MsoNormal style= "MARGIN: 0cm 0cm 0pt> <SPAN style= "FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt "> 浸四氟苎麻盘根、高水基盘根、高档油浸棉纱盘根、普通油浸棉纱盘根、 <SPAN lang=EN-US> <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office " /> <o:p> </o:p> </SPAN> </SPAN> </P> <P class=MsoNormal style= "MARGIN: 0cm 0cm 0pt "> <SPAN style= "FONT-SIZE: 9pt; FONT-FAMILY: 宋体; mso-bidi-font-family: 宋体; mso-font-kerning: 0pt "> 纤维类盘根应用广泛, <SPAN lang=EN-US> </SPAN> 根据各自不同的优良性能可用于 </SPAN
------解决方案--------------------string s = ps.PIntro.ToString();
string strhtml = Regex.Replace(s, " <.+?> ", " ");
strhtml = Regex.Replace(strhtml, " <br> ", "[br] ",RegexOptions.IgnoreCase);
ps.PIntro = ps.PIntro.Replace(s, strhtml);
ps.PIntro = ps.PIntro.Replace( " ' ", " ' ' ");
ps.PIntro = ps.PIntro.Replace( " ", " ");
ps.PIntro = ps.PIntro.Replace( "& ldquo; ", " ");
ps.PIntro = ps.PIntro.Replace( "& rdquo; ", " ");
------解决方案--------------------ps.PIntro = ps.PIntro.Replace( " </P> ", " </br> ");
或者这样,把其他都过滤,就留个br,你先试试
ps.pintro 是我的字段 名
------解决方案--------------------html = Regex.Replace(html, @ "(^[^ <> ]*> )|( <[^ <> ]*$) ", " ", RegexOptions.IgnoreCase);
过滤半个标签
------解决方案--------------------用这个正则 <[^ <]*> 可以找到所有有HTML标签,你只要把它过滤掉行就行..