ASP是使用正则提取内容里所有图片路径SRC的实现代码
函数
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)
到这里就为拿出了,大家可以根据需要修改。
您可能感兴趣的文章
- 01-11ASP新手必备的基础知识
- 01-11ASP实现加法验证码
- 01-11asp服务器如何搭建
- 01-11ASP脚本组件实现服务器重启
- 01-11ASP动态网页制作技术经验分享
- 01-11ASP实现类似hashMap功能的类
- 01-11ASP编码必备的8条原则
- 01-11解决ASP中http状态跳转返回错误页的问题
- 01-11ASP程序中常用的脚本语言
- 01-11ASP中用select case代替其他语言中的switch case, default用case else