ASP删除img标签的style属性只保留src的正则函数(删除一个img元素的标题)这都可以?

随心笔谈12个月前发布 admin
100 0


Function FixImg(sString)
  
    Dim sReallyDo, regEx, iReallyDo
    Dim oMatches, cMatch
    Dim tStartTime, tEndTime
    If IsNull(sString) Then
        FixImg=””
        Exit Function
    End If
    sReallyDo=sString
    On Error Resume Next
    sReallyDo=Replace(sReallyDo, vbCr, ” “)
    sReallyDo=Replace(sReallyDo, vbLf, ” “)
    sReallyDo=Replace(sReallyDo, vbTab, ” “)
    sReallyDo=Replace(sReallyDo, “<img “, vbCrLf & “<img “, 1, -1, 1)
    sReallyDo=Replace(sReallyDo, “/>”, ” />”, 1, -1, 1)
    sReallyDo=ReplaceAll(sReallyDo, “=”, “=”, True)
    sReallyDo=ReplaceAll(sReallyDo, “> “, “>”, True)
    sReallyDo=Replace(sReallyDo, “><“, “>” & vbCrLf & “<“)
    sReallyDo=Trim(sReallyDo)
    On Error GoTo 0
    Set regEx=New RegExp
    regEx.IgnoreCase=True
    regEx.Global=True
    ‘//去除onclick,onload等脚本
    regEx.Pattern=”\s[on].+?=([“”|\’])(.*?)\1”
    sReallyDo=regEx.Replace(sReallyDo, “”)
    ‘//将SRC不带引号的图片地址加上引号
    regEx.Pattern=”<img.*?\ssrc=https://www.jb51.net/article/([^””\’\s][^””\’\s>]*).*?>”
    sReallyDo=regEx.Replace(sReallyDo, “<img src=”https://www.jb51.net/article/”$1″” />”)
    ‘//正则匹配图片SRC地址
    regEx.Pattern=”<img.*?\ssrc=https://www.jb51.net/article/([“”\’])([^””\’]+?)\1.*?>”
    sReallyDo=regEx.Replace(sReallyDo, “<img src=”https://www.jb51.net/article/”$2″” />”)
    FixImg=sReallyDo
End Function

© 版权声明

相关文章