Function RegImg(TheStr)
Dim RegEx
Set RegEx = New RegExp '建立正則表達對象。
RegEx.IgnoreCase =True ' 是否區(qū)分大小寫,True為不區(qū)分且默認
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) ' 執(zhí)行搜索。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