远程提取新闻网页,然后用正则表达式取出不需要的html语言现有一段founction如下:
我已将其中的空格、换行等去掉
现在就是要过滤<!-- 和//-->之间的东西<!--functionopenWithSelfMain(url,name,width,height,top,left,noscrollbars){width2=(width<=screen.width)?width:(screen.width*3/4);height2=(height<=screen.height)?height:(screen.height*3/4);varoptions="width="+width2+",height="+height2;if(top!="")options+=",top="+top;if(left!="")options+=",left="+left;options+="toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,copyhistory=no";if(noscrollbars==null||noscrollbars==""||noscrollbars=="0"||width>screen.width||height>screen.height){options+=",scrollbars=yes";}else{options+=",scrollbars=no";}//alert(width+">>"+height);//returnfalse;new_window=window.open(url,name,options);window.self.name="main";new_window.focus();}//--> 如何把这段去掉,其中有字符、数字、标点符号等
这个正则表达式可以写出来吗?
我已将其中的空格、换行等去掉
现在就是要过滤<!-- 和//-->之间的东西<!--functionopenWithSelfMain(url,name,width,height,top,left,noscrollbars){width2=(width<=screen.width)?width:(screen.width*3/4);height2=(height<=screen.height)?height:(screen.height*3/4);varoptions="width="+width2+",height="+height2;if(top!="")options+=",top="+top;if(left!="")options+=",left="+left;options+="toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,copyhistory=no";if(noscrollbars==null||noscrollbars==""||noscrollbars=="0"||width>screen.width||height>screen.height){options+=",scrollbars=yes";}else{options+=",scrollbars=no";}//alert(width+">>"+height);//returnfalse;new_window=window.open(url,name,options);window.self.name="main";new_window.focus();}//--> 如何把这段去掉,其中有字符、数字、标点符号等
这个正则表达式可以写出来吗?
简单点吧,不知道可行否
描述返回一个字符串,该字符串中指定的子字符串已被替换成另一子字符串,并且替换发生的次数也是指定的。语法Replace(expression, find, replacewith[, start[, count[, compare]]])Replace函数语法有如下几部分:部分 描述
expression 必需的。字符串表达式,包含要替换的子字符串。
find 必需的。要搜索到的子字符串。
replacewith 必需的。用来替换的子字符串。
start 可选的。在表达式中子字符串搜索的开始位置。如果忽略,假定从1开始。
count 可选的。子字符串进行替换的次数。如果忽略,缺省值是 –1,它表明进行所有可能的替换。
compare 可选的。数字值,表示判别子字符串时所用的比较方式。关于其值,请参阅“设置值”部分。
设置值compare参数的设置值如下:常数 值 描述
vbUseCompareOption –1 使用Option Compare语句的设置值来执行比较。
vbBinaryCompare 0 执行二进制比较。
vbTextCompare 1 执行文字比较。
vbDatabaseCompare 2 仅用于Microsoft Access。基于您的数据库的信息执行比较。
返回值Replace的返回值如下:如果 Replace返回值
expression长度为零 零长度字符串("")。
expression为Null 一个错误。
find长度为零 expression的复本。
replacewith长度为零 expression的复本,其中删除了所有出现的find 的字符串。
start > Len(expression) 长度为零的字符串。
count is 0 expression.的复本。
说明Replace函数的返回值是一个字符串,但是,其中从start所指定的位置开始,到expression字符串的结尾处的一段子字符串已经发生过替换动作。并不是原字符串从头到尾的一个复制。
Set Re = New RegExp
Re.Global = True
Re.IgnoreCase = True
WebBody = Trim(WebBody)
Re.Pattern = "<!--(.*)-->"
Zm = Re.Replace(WebBody, "")
End Function用这ZM应该可以的噢!
我就是这样写的,程序报错!!实时错误5018
应用程序定义和对象定义错误,并停在Re.Replace这一行奈何!!