在 JScript 表达式中,正则表达式后面的全局标志 ('g') 表示该表达式将用来在输入字符串中查找尽可能多的匹配。大小写敏感性由表达式结束处的大小写敏感性标记 ('i') 指定。多行标记('m')指定可能出现在换行符的两端的潜在匹配。对 VBScript 而言,在表达式中不能设置各种标记,但必须使用 RegExp 对象的属性来显式设置。使用上面所示的正则表达式,下面的 JScript 代码可以使用子匹配信息,在一个文字字符串中将连续出现两次的相同单词替换为一个相同的单词:var ss = "Is is the cost of of gasoline going up up?.\n";
var re = /\b([a-z]+) \1\b/gim;       // 创建正则表达式样式。
var rv = ss.replace(re,"$1");   // 用一个单词替代两个单词。
最接近的等价 VBScript 代码如下:Dim ss, re, rv
ss = "Is is the cost of of gasoline going up up?." & vbNewLine
Set re = New RegExp
re.Pattern = "\b([a-z]+) \1\b"
re.Global = True
re.IgnoreCase = True
re.MultiLine = True
rv = re.Replace(ss,"$1")
请注意在 VBScript 代码中,全局、大小写敏感性以及多行标记都是使用 RegExp 对象的适当属性来设置的。

解决方案 »

  1.   

    不对啊,如下,我想替换html到body这部份
    <html>
    <head>
    <title> New Document </title>
    <meta name="Generator" content="EditPlus">
    <meta name="Author" content="">
    <meta name="Keywords" content="">
    <meta name="Description" content="">
    </head><body></body>
    </html>
    <script language="JavaScript">
    <!--
    var reg=/.+body/gim
    alert(document.documentElement.outerHTML.replace(reg,""))
    //-->
    </script>
      

  2.   

    用不着多行,因为你要的是连断行和空行都要替换,
    你可以试下,当你只是设置多行时,它会只是把找到去了,下了一个空行<textarea onclick="alert(this.value.replace(/< *htm[\s\S]*< *body *>/gim,'') )">
    <html>
    <head>
    <title> New Document </title>
    <meta name="Generator" content="EditPlus">
    <meta name="Author" content="">
    <meta name="Keywords" content="">
    <meta name="Description" content="">
    </head><body></body>
    </html>
    <script language="JavaScript">
    <!--
    var reg=/.+body/gim
    alert(document.documentElement.outerHTML.replace(reg,""))
    //-->
    </script>
    </textarea>