用正则和xmlHttp实现的asp小偷程序(2)
Else
NextCharCode = AscB(MidB(vIn,i+1,1))
strReturn = strReturn & Chr (CLng(ThisCharCode) * &H100 + CInt(NextCharCode))
i = i + 1
End If
Next
bytes2BSTR = strReturn
End Function
'---------------------------------------------------------------
public Function SearchReplace(strContent,ReplaceReg,ResultReg)
'替换,将strContent中的replaceReg描述的字符串用resultReg描述的替换,返回到searchReplace去
'将正则的replace封装了。
oReg.Pattern=ReplaceReg
SearchReplace=oReg.replace(strContent,ResultReg)
End Function
'---------------------------------------------------------------
public Function AbsoluteURL(strContent,byval url)
'将strContent中的相对URL变成oXmlHttp中指定的url的绝对地址(http/https/ftp/mailto:)
'正则可以修改修改。
dim tempReg
set tempReg=new RegExp
tempReg.IgnoreCase=true
tempReg.Global=true
tempReg.Pattern="(^.*\/).*$"'含文件名的标准路径http://www.wrclub.net/default.aspx
Url=tempReg.replace(url,"$1")
tempReg.Pattern="((?:src|href).*?=[\'\u0022](?!ftp|http|https|mailto))"
AbsoluteURL=tempReg.replace(strContent,"$1"+Url)
set tempReg=nothing
end Function
'---------------------------------------------------------------
end class
'========================================
%>
<%'例子
Response.CharSet = "GB2312"
dim mySearch
set mySearch=new EngineerSearch
'URL一定是包含文件扩展名的完整地址,结果是集合,集合中的每个项目是数组,应该这样引用子查询:myMatches(0).subMatches(0)
set myMatches=mySearch.engineer("http://www.wrclub.net/default.aspx","<img.*?>")
if myMatches.count=0 Then
response.write "没有你正则的字符串"
end if
if myMatches.count>0 then
response.write myMatches.count&"<br>"
for each key in myMatches
response.write key.firstindex&":"&cstr(key.value)&"<br>"
next
end if
%>
更诸多的应用,只要你会正则