Set Reg = New RegExp Reg.Global = True Reg.IgnoreCase = True Reg.Pattern="<!--BeginID:4719-->[\s\S]*?<!--EndThisOfAllId-->" If Reg.Test(sToHtml) Then Set Matchs2=Reg.Execute(sToHtml)
b=0 For Each Match2 In Matchs2 Set RegEx = New RegExp RegEx.Pattern=Match2 RegEx.Global = false RegEx.IgnoreCase = True sToHtml=RegEx.Replace(sToHtml,b) b=b+1 Next End If Set Reg=Nothing
Set Reg = New RegExp Reg.Global = false Reg.IgnoreCase = true Reg.Pattern="<!--BeginID:4719-->[\s\S]*?<!--EndThisOfAllId-->" b=0 while Reg.Test(sToHtml) sToHtml=Reg.Replace(sToHtml,b) b=b+1 Wend Set Reg=Nothing
Reg.Pattern="<!--BeginID:4719-->([\s\S](?!(<!--EndThisOfAllId-->)))*<!--EndThisOfAllId-->"
Reg.Pattern="<!--BeginID:4719-->([\s\S](?!(<!--BeginID:4719-->)))*<!--EndThisOfAllId-->"
我再去测试下
sToHtml="<!--BeginID:4719-->asd<!--EndThisOfAllId--><!--BeginID:4719-->asd<!--EndThisOfAllId-->"
Set Reg = New RegExp
Reg.Global = True
Reg.IgnoreCase = True
Reg.Pattern="<!--BeginID:4719-->[\s\S]*?<!--EndThisOfAllId-->"
If Reg.Test(sToHtml) Then
Set Matchs2=Reg.Execute(sToHtml)
b=0
For Each Match2 In Matchs2
Set RegEx = New RegExp
RegEx.Pattern=Match2
RegEx.Global = false
RegEx.IgnoreCase = True
sToHtml=RegEx.Replace(sToHtml,b)
b=b+1
Next
End If
Set Reg=Nothing
msgbox(sToHtml)
</script>
<script language=vbscript>
sToHtml="<!--BeginID:4719-->asd<!--EndThisOfAllId--><!--BeginID:4719-->asd<!--EndThisOfAllId-->"
Set Reg = New RegExp
Reg.Global = false
Reg.IgnoreCase = true
Reg.Pattern="<!--BeginID:4719-->[\s\S]*?<!--EndThisOfAllId-->"
b=0
while Reg.Test(sToHtml)
sToHtml=Reg.Replace(sToHtml,b)
b=b+1
Wend
Set Reg=Nothing
msgbox(sToHtml)
</script>
<!--BeginID:2-->这里是部分内容2<!--EndThisOfAllId-->
<!--BeginID:3-->这里是部分内容3<!--EndThisOfAllId-->------------------------------------------b.htm 中核心内容--------------------<!--BeginID:1-->新内容1<!--EndThisOfAllId-->
<!--BeginID:2-->新内容2<!--EndThisOfAllId-->
<!--BeginID:3-->新内容3<!--EndThisOfAllId-->我想将 b.htm 中对应的内容替换 a.htm 中对应的内容。同时替换后要保留 <!--BeginID:1--><!--EndThisOfAllId--> 这样的标签,以便下次再次进行替换!
b.htm 中的内容直接装在数组里a(0)="<!--BeginID:1-->新内容1<!--EndThisOfAllId-->"
a(1)="<!--BeginID:1-->新内容2<!--EndThisOfAllId-->"
a(2)="<!--BeginID:1-->新内容3<!--EndThisOfAllId-->"