正则匹配替换的问题,请正则高手帮忙看看!
要进行处理的内容:
<table id=formname style="BORDER-RIGHT: 1px dotted; BORDER-TOP: 1px dotted; BORDER-LEFT: 1px dotted; BORDER-BOTTOM: 1px dotted; BORDER-COLLAPSE: collapse" borderColor=#ff0000 cellPadding=0 width="99%" border=1>
<tr>
<td>
<FORM name=33 action=3333 method=post> </FORM></td>
</tr>
</table>
<table borderColor=#ff0000 cellPadding=0 width="99%" border=1>
<tr>
<td>jfsdhjsdkfs</td>
</tr>
</table>
<table id=formname style="BORDER-RIGHT: 1px dotted; BORDER-TOP: 1px dotted; BORDER-LEFT: 1px dotted; BORDER-BOTTOM: 1px dotted; BORDER-COLLAPSE: collapse" borderColor=#ff0000 cellPadding=0 width="99%" border=1>
<tr>
<td>
<FORM name=2232 action=22322 method=post> </FORM></td>
</tr>
</table>
我需要对上面的内容进行处理,把Form前后的表格代码去除,也就是说,每一个FORM表单,都会放在一个格式的固定表格内,并且对表格定义ID=formname来判断这个表格的存在是否是因为FORM表单的需要。那么现在的要求就是把表单外面的表格去掉,上面的这段代码,是由三个表格组成的,但是只有第一个和第三个是需要去掉的,第二个不需要,判断条件就是Table里面是否存在ID=formname的标签。
我自己写了一个正则来进行处理:
<script language="VBScript">
function setContent(strvalue)
Set regEx = New RegExp
regEx.IgnoreCase = True
regEx.Global = True
regEx.Pattern = "(\<table id=formname)(.[^\<]*)(\<\/table\)"
Set Matches = regEx.Execute(strvalue)
For Each Match In Matches
regEx.Pattern = "\<td\>(.*)\<\/td\>"
Set strTemp = regEx.Execute(Match.Value)
For Each Match2 In strTemp
strTemp2 = Replace(Match2.Value, "?", "?")
strTemp2 = Replace(strTemp2, "&", "&")
strTemp2 = Replace(strTemp2, "#", "")
strTemp2 = Replace(strTemp2,"&13;&10;",vbCrLf)
strTemp2 = Replace(strTemp2,"&9;",vbTab)
strvalue = Replace(strvalue, Match.Value, strTemp2)
strvalue = Replace(strvalue, Match.Value, strTemp2)
Next
Next
end function
</script>
就是无法进行替换,后来我发现应该是这段代码被换行(存在vbTab和vbCrLf)了的原因,但是我对这两个处理了之后,最后的几个</td></tr></table>就是无法也放在一行,不知道为什么?!
我想可能我的思路不正确,请正则高手帮我一下,怎么样对这段代码进行处理更好一些?!
目的只有一个,就是把含有Id=formname标签的表格去掉,只保留里面的FORM表单代码。