当前位置: 移动技术网 > IT编程>开发语言>Asp > ASP是使用正则提取内容里所有图片路径SRC的实现代码

ASP是使用正则提取内容里所有图片路径SRC的实现代码

2019年10月01日  | 移动技术网IT编程  | 我要评论

函数

function regimg(thestr)
    dim regex
    set regex = new regexp '建立正则表达对象。
    regex.ignorecase =true ' 是否区分大小写,true为不区分且默认
    regex.global = true '全部匹配还是只匹配第一个 
    regex.pattern = "<img[^>]*src\s*=\s*['"&chr(34)&"]?([\w/\-\:.]*)['"&chr(34)&"]?[^>]*>" ' 搜索所使用的正则表达式
    if regex.test(thestr) then  ' 判断是否有匹配值,返回true或者false。不受global属性影响。
        dim matches
        set matches = regex.execute(thestr) ' 执行搜索。execute 方法返回一个matches 集合,其中包含了在 thestr 中找到的每一个匹配的 match 对象。如果未找到匹配,execute 将返回空的 matches 集合。
        for each match in matches ' 遍历匹配集合。
        'retstr = retstr & match.value & "<br />" '获取整个img
        retstr = retstr & match.submatches(0)&"||" '只取src
        next
        regimg = retstr
    end if           
end function

'调用方法
htmlbody="<img id='img'  src='/images/01.jpg' alt='图片标题' style='border:none;position:relative;' /><img  src='/111.jpg' /><img  src='/222.jpg' />"
response.write regimg(htmlbody)

到这里就为拿出了,大家可以根据需要修改。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网