使用正則表達式提取內容串中的圖片連接

Function getimgsrc(str)
    dim tagnum,tagnums,imgtag
    getimgsrc=""
    str=Replace(str,"""",chr(32))
    str=Replace(str,">",chr(32)&"end")
    'response.write str
    Set imgtag = New Regexp'設置配置對象
    imgtag.IgnoreCase = True '忽略大小寫
    imgtag.Global = True '設置爲全文搜索
    imgtag.Pattern = "<img.+?"&chr(32)&"end"'首先找到裏面的<img.src>屬性
    strs=trim(str)
    Set tagnums =imgtag.Execute(strs) '開始執行配置
    For Each tagnum in tagnums
        if tagnum.Value<>"" then
            getimgsrc = getimgsrc&getsrcs(tagnum.Value) '執行第二輪的匹配
        end if
    Next
End Function

Function getsrcs(str)
    dim srcnum,srcnums,imgsrc
    getsrcs=""
    Set imgsrc = New Regexp
        imgsrc.IgnoreCase = True
    imgsrc.Global = True
    imgsrc.Pattern = "http://.+?"&chr(32) '取出裏面的地址
    set srcnums=imgsrc.Execute(str)
    For Each srcnum in srcnums
        if srcnum.Value<>"" then
            getsrcs=getsrcs&"<p><img src="""&left(srcnum.Value,len(srcnum.Value)-1)&""" οnlοad=""DrawImage(this);"" οnclick=""OpenImage(this);""></p>"&VbCrLf '把裏面的地址串起來備用
        end if
    next
End Function 
<script src="http://pagead2.googlesyndication.com/pagead/show_ads.js" type="text/javascript"> </script>  
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章