本文介绍了正则表达式来替换多个html属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个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"> </td>
<td class="xl65" dir="rtl" width="64"><strong></strong></td>
</tr>
<tr height="20">
<td class="xl67" dir="rtl" width="64" height="20"> </td>
<td class="xl66" dir="ltr" width="64">T3500 </td>
</tr>
<tr height="20">
<td class="xl68" width="64" height="20"> </td>
<td> </td>
</tr>
<tr height="20">
<td height="20"> </td>
<td class="xl65" dir="rtl" width="64"><strong></strong></td>
</tr>
<tr height="48">
<td class="xl67" dir="rtl" width="64" height="48"> </td>
<td class="xl66" dir="ltr" width="64">Intel® X58 Chipset </td>
</tr>
<tr height="33">
<td class="xl70" dir="rtl" width="64" height="33"> </td>
<td class="xl69" dir="ltr" width="64">10/100/1000 </td>
</tr>
<tr height="20">
<td class="xl68" width="64" height="20"> </td>
<td> </td>
</tr>
<tr height="20">
<td height="20"> </td>
<td class="xl65" dir="rtl" width="64"><strong></strong></td>
</tr>
<tr height="96">
<td class="xl67" dir="rtl" width="64" height="96"> </td>
<td class="xl66" dir="ltr" width="64">One Intel Xeon W3503(2.4GHz,4.8GT/s,4MB,DC) </td>
</tr>
<tr height="20">
<td class="xl68" width="64" height="20"> </td>
<td> </td>
</tr>
</tbody>
</table>
我想将所有样式,目录,高度,宽度和类替换为空白
i want to replace all style, dir, height, width and class with nothing so it will be removed
这是我为其中的一些人尝试的,它在在线测试程序中工作,但在记事本++中无效
this is what i have tried for some of them and it worked in an online tester but didn't work in notepad++
( class=\"([^\"]*)\"){0,} (width=\"([^\"]*)\"){0,} (height=\"([^\"]*)\"){0,}
推荐答案
试试
Try
\s*(?:style|dir|height|width|class)\s*=\s*"[^"]*"\s*
当然,这将删除文本,比如 style =hello
,无论它们出现在哪里,也都在标签之外。
Of course this will remove texts like style="hello"
wherever they may occur, also outside of tags.
可能Notepad ++不支持 \ s
简写。尝试使用
It may be that Notepad++ doesn't support the \s
shorthand. Try using
[ ]*(?:style|dir|height|width|class) *= *"[^"]*" *
改为看看是否有效。 []
在开始时可以被替换为一个空格。
instead and see if that works. The [ ]
at the start can be replaced by a single space.
这篇关于正则表达式来替换多个html属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!