Asp正则表达式提取内容中的图片

来源:互联网 发布:关于借钱的网络段子 编辑:程序博客网 时间:2024/05/16 09:03

<%
FunctionRegImg(TheStr)
    DimRegEx
    SetRegEx=NewRegExp'建立正则表达对象。
    RegEx.IgnoreCase=True' 是否区分大小写,True为不区分且默认
    RegEx.Global=True'全部匹配还是只匹配第一个
    RegEx.Pattern="<img[^>]*src\s*=\s*['"&CHR(34)&"]?([\w/\-\:.]*)['"&CHR(34)&"]?[^>]*>"' 搜索所使用的正则表达式
    IfRegex.test(TheStr)Then  ' 判断是否有匹配值,返回True或者False。不受Global属性影响。
        DimMatches
        SetMatches=RegEx.Execute(TheStr)' 执行搜索。Execute 方法返回一个Matches 集合,其中包含了在 TheStr 中找到的每一个匹配的 Match 对象。如果未找到匹配,Execute 将返回空的 Matches 集合。
        ForEachMatchinMatches' 遍历匹配集合。
        RetStr=RetStr&Match.Value&"<br />"'获取整个img
        RetStr=RetStr&Match.SubMatches(0)'只取src
        Next
        RegImg=RetStr
    EndIf          
EndFunction
Response.WriteRegImg("<p><img src=""http://www.wdssmq.com/UPLOAD/cbfs.gif"" width=""132"" height=""132"" alt=""111"" /></p>")
%>


原创粉丝点击