提取一段内容中的所有图片或者图片地址<%Function RegImg(TheStr)
Dim RegEx
Set RegEx = New RegExp
RegEx.IgnoreCase =True
RegEx.Global = True
RegEx.Pattern = "<img[^>]*src\s*=\s*['"&CHR(34)&"]?([\w/\-\:.]*)['"&CHR(34)&"]?[^>]*>"
If Regex.test(TheStr) then
Dim Matches
Set Matches = RegEx.Execute(TheStr) ' 执行搜索。
For Each Match in Matches ' 遍历匹配集合。
RetStr = RetStr & Match.Value & "<br />" '获取整个img
RetStr = RetStr & Match.SubMatches(0) '只取src
Next
RegImg = RetStr
End If
End Function%>
调用方法:
本文介绍了一种使用正则表达式从HTML内容中提取图片地址的方法。通过定义特定的正则表达式模式,可以准确地抓取<img>标签内的src属性,从而实现图片地址的有效提取。
706

被折叠的 条评论
为什么被折叠?



