你的第一点和第三点有些不明确
第二个<!--BeginID:1-->应该替换成和上面<!--BeginID:1-->的一样还是第一点所说的依次替换?

解决方案 »

  1.   

    <textarea name="textarea1">
    <!--BeginID:1-->这里是部分内容1<!--EndThisOfAllId-->
    <!--BeginID:2-->这里是部分内容2<!--EndThisOfAllId-->
    <!--BeginID:3-->这里是部分内容3<!--EndThisOfAllId-->
    <!--BeginID:1-->这里是部分内容1<!--EndThisOfAllId-->
    </textarea>
    <script language=vbscript>
    dim str
    str=document.all.textarea1.value
    dim a(3)
    a(0)="<!--BeginID:1-->新内容1<!--EndThisOfAllId-->"
    a(1)="<!--BeginID:2-->新内容2<!--EndThisOfAllId-->"
    a(2)="<!--BeginID:3-->新内容3<!--EndThisOfAllId-->"
    a(3)="<!--BeginID:1-->新内容1<!--EndThisOfAllId-->"
    set   regEx=new   regExp   
    regEx.Pattern="(<!--BeginID:(\d+)-->)(.+?)(<!--EndThisOfAllId-->)"   
    regEx.IgnoreCase=true 
    for i=0  to ubound(a)
    a(i)=regEx.replace(a(i),"$3")
    str=regEx.replace(str,"###Begin$2ID"&a(i)&"###End")
    next
    regEx.Pattern="###Begin(\d+)ID"   
    regEx.IgnoreCase=true
    regEx.Global=True
    str=regEx.replace(str,"<!--BeginID:$1-->")
    regEx.Pattern="###End"   
    regEx.IgnoreCase=true
    regEx.Global=True
    str=regEx.replace(str,"<!--EndThisOfAllId-->")
    set regEx=nothing
    msgbox str
    </script>
      

  2.   

    首先谢谢你哈不过我觉得你这个不通用。比如a(0)="<!--BeginID:1-->新内容1<!--EndThisOfAllId-->" 这里是理想化的,假如中间是一段 html 代码,怎么办?
      

  3.   

    我把问题简单化说吧:<%  
                   dim a(1) 
                   a(0)="<!--BeginID:4719-->第一部分<!--EndThisOfAllId-->"
                   a(1)="<!--BeginID:4719-->第二部分<!--EndThisOfAllId-->"
                   
                   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,a(b))
                         b=b+1 
                   Wend  
                   Set  Reg=Nothing             response.write sToHtml%>
        我就是想做到把变量 <!--BeginID:4719-->asd<!--EndThisOfAllId--> 中的字符串替换成 数组 a 中的内容     但我发现如果 数组 a 中含 <!--BeginID:4719-->asd<!--EndThisOfAllId--> 字符串的话就无法得到预期的结果。