日期:2014-05-16  浏览次数:20391 次

求一段正则式
<TABLE style="WIDTH: 270pt; BORDER-COLLAPSE: collapse" border=0 cellSpacing=0 cellPadding=0 width=360>
<COLGROUP>
<COL style="WIDTH: 54pt" span=5 width=72>
<TBODY>
<TR style="HEIGHT: 13.5pt; mso-height-source: userset" height=18>
<TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent; WIDTH: 108pt; HEIGHT: 13.5pt; BORDER-TOP: windowtext 0.5pt solid; BORDER-RIGHT: windowtext 0.5pt solid" class=xl67 height=18 width=144 colSpan=2><FONT face=宋体>单位</FONT></TD>
<TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent; WIDTH: 54pt; BORDER-TOP: windowtext 0.5pt solid; BORDER-RIGHT: windowtext 0.5pt solid" class=xl68 rowSpan=2 width=72><FONT face=宋体>人次</FONT></TD>
<TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent; WIDTH: 108pt; BORDER-TOP: windowtext 0.5pt solid; BORDER-RIGHT: windowtext 0.5pt solid" class=xl66 rowSpan=2 width=144 colSpan=2><FONT face=宋体>备注</FONT></TD></TR>
<TR style="HEIGHT: 13.5pt" height=18>
<TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent; HEIGHT: 13.5pt; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl65 height=18><FONT face=宋体>名称</FONT></TD>
<TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext; BACKGROUND-COLOR: transparent; BORDER-TOP: windowtext; BORDER-RIGHT: windowtext 0.5pt solid" class=xl65><FONT face=宋体>地址</FONT></TD></TR></TBODY></TABLE>
================================================================
现在求一段正则表达式,能够使上述输出为
<table>
<tbody>
<tr>
<td colSpan="2">单位</td>
<td rowSpan="2">人次</td>
<td rowSpan="2" colSpan="2">备注</td>
</tr>
<tr>
<td>名称</td>
<td>地址</td>
</tr>
</tbody>
</table>

------解决方案--------------------
/<table([^>]*?)>(.*?)<tbody>\n<tr([^>]*?)>(\n<td([^>]*?)>(<([^>]*?)>).*?<([^>]*?)><\/td>)+<\/tr>\n<tr([^>]*?)>(\n<td([^>]*?)>(<([^>]*?)>).*?<([^>]*?)><\/td>)+<\/tr><\/tbody><\/table>/gi
------解决方案--------------------
HTML code
<script type="text/javascript">
var html = '<TABLE style="WIDTH: 270pt; BORDER-COLLAPSE: collapse" border=0 cellSpacing=0 cellPadding=0 width=360>'+
'<COLGROUP>'+
'<COL style="WIDTH: 54pt" span=5 width=72>'+
'<TBODY>'+
'<TR style="HEIGHT: 13.5pt; mso-height-source: userset" height=18>'+
'<TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent; WIDTH: 108pt; HEIGHT: 13.5pt; BORDER-TOP: windowtext 0.5pt solid; BORDER-RIGHT: windowtext 0.5pt solid" class=xl67 height=18 width=144 colSpan=2><FONT face=宋体>单位</FONT></TD>'+
'<TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent; WIDTH: 54pt; BORDER-TOP: windowtext 0.5pt solid; BORDER-RIGHT: windowtext 0.5pt solid" class=xl68 rowSpan=2 width=72><FONT face=宋体>人次</FONT></TD>'+
'<TD style="BORDER-BOTTOM: windowtext 0.5pt solid; BORDER-LEFT: windowtext 0.5pt solid; BACKGROUND-COLOR: transparent; WIDTH: