asp提取文档中的附件链接

2012-05-24  金城  1861

<%

'' 提取文档中的附件链接,返回数组

function PickAttachment(html,ext)
 Dim regEx,str1,s
 str1 = html &""
 s=""
 Set regEx = New RegExp
 regEx.Pattern = "<(img|a)[^>]*(src|href)\s?=['""]?[^\s>'""]*\.("&ext&")['""]?[^>]*>"
 ''response.Write("<br>" &regEx.pattern)
 regEx.IgnoreCase = True
 regEx.Global = True

 set Matches = regEx.execute(str1)
 for each match in Matches
  s = s &"|" &regExReplace(match.value,"<.*(src|href)\s?=['""]?([^\s>'""]*)['""]?[^>]*>$","$2")
 next
 set Matches=nothing
 if s="" then
  PickAttachment=Empty
 else
  s=regExReplace(s,"^\|","")
  PickAttachment=split(s,"|")
 end if
end function

'' 使用方法

attachmentArr=PickAttachment(content,"gif|bmp|jpg|rar|doc|png|swf|zip|docx")
if isArray(attachmentArr) then
for each att in attachmentArr
 '' TODO
next
end if
%>