2011-01-06 56 views
2

我有这个网站:正则表达式来替换多个HTML属性

<table style="width: 128px;" border="0" cellspacing="0" cellpadding="0"> 
<colgroup span="1"><col span="2" width="64"></col></colgroup> 
<tbody> 
<tr height="20"> 
<td width="64" height="20">&nbsp;</td> 
<td class="xl65" dir="rtl" width="64"><strong></strong></td> 
</tr> 
<tr height="20"> 
<td class="xl67" dir="rtl" width="64" height="20">&nbsp;</td> 
<td class="xl66" dir="ltr" width="64">T3500&nbsp;</td> 
</tr> 
<tr height="20"> 
<td class="xl68" width="64" height="20">&nbsp;</td> 
<td>&nbsp;</td> 
</tr> 
<tr height="20"> 
<td height="20">&nbsp;</td> 
<td class="xl65" dir="rtl" width="64"><strong></strong></td> 
</tr> 
<tr height="48"> 
<td class="xl67" dir="rtl" width="64" height="48">&nbsp;</td> 
<td class="xl66" dir="ltr" width="64">Intel&reg; X58 Chipset&nbsp;</td> 
</tr> 
<tr height="33"> 
<td class="xl70" dir="rtl" width="64" height="33">&nbsp;</td> 
<td class="xl69" dir="ltr" width="64">10/100/1000&nbsp;</td> 
</tr> 
<tr height="20"> 
<td class="xl68" width="64" height="20">&nbsp;</td> 
<td>&nbsp;</td> 
</tr> 
<tr height="20"> 
<td height="20">&nbsp;</td> 
<td class="xl65" dir="rtl" width="64"><strong></strong></td> 
</tr> 
<tr height="96"> 
<td class="xl67" dir="rtl" width="64" height="96">&nbsp;</td> 
<td class="xl66" dir="ltr" width="64">One Intel Xeon W3503(2.4GHz,4.8GT/s,4MB,DC)&nbsp;</td> 
</tr> 
<tr height="20"> 
<td class="xl68" width="64" height="20">&nbsp;</td> 
<td>&nbsp;</td> 
</tr> 
</tbody> 
</table> 

我想要替换所有样式,目录,高度,宽度和类没有那么它将被删除

这是什么我已经尝试了其中的一些,它在在线测试仪的工作,但在记事本++

(class=\"([^\"]*)\"){0,} (width=\"([^\"]*)\"){0,} (height=\"([^\"]*)\"){0,} 

回答

5

没有工作尝试

\s*(?:style|dir|height|width|class)\s*=\s*"[^"]*"\s* 

当然,这将删除像style="hello"这样的文本,无论它们在何处发生,也在标签之外。

这可能是记事本++不支持\s速记。尝试使用

[ ]*(?:style|dir|height|width|class) *= *"[^"]*" * 

取而代之,看看是否有效。开始时的[ ]可以被一个空格替换。

+0

改变了它to:\ s *(?: style | dir | height | width | class)\ s * = \ s *“[^”] *“它可以在在线测试仪中使用,但在记事本++中不起作用 – 2011-01-06 07:52:44

1

这应该做的伎俩,至少在你的例子:

\ s *(风格| DIR |高度|宽度|类别)= “[^”] +“\ S *