函數
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)
到這里就為拿出了,大家可以根據需要修改。
新聞熱點
疑難解答