当前位置: 移动技术网 > IT编程>开发语言>正则 > asp常用的正则表达式实现字符串的替换

asp常用的正则表达式实现字符串的替换

2017年12月12日  | 移动技术网IT编程  | 我要评论
去除html标签正则<\/*[^<>]*>
function losehtml(contentstr)
    dim clstemplosestr,regex
        clstemplosestr = cstr(contentstr)
    set regex = new regexp
        regex.pattern = "<\/*[^<>]*>"
        regex.ignorecase = true
        regex.global = true
    clstemplosestr = regex.replace(clstemplosestr,"")
    set regex = nothing
    losehtml = clstemplosestr
end function
去除网页中的class
function loseclasstag(contentstr)
    dim clstemplosestr,regex
        clstemplosestr = cstr(contentstr)
    set regex = new regexp
        regex.pattern = "(class=){1,}(""|\'){0,1}\s+(""|\'|>|\s){0,1}"
        regex.ignorecase = true
        regex.global = true
    clstemplosestr = regex.replace(clstemplosestr,"")
    loseclasstag = clstemplosestr
    set regex = nothing
end function

function losescripttag(contentstr)
    dim clstemplosestr,regex
        clstemplosestr = cstr(contentstr)
    set regex = new regexp
        regex.pattern = "(<script){1,}[^<>]*>[^\0]*(<\/script>){1,}"
        regex.ignorecase = true
        regex.global = true
    clstemplosestr = regex.replace(clstemplosestr,"")
    losescripttag = clstemplosestr
    set regex = nothing
end function

function loseiframetag(contentstr)
    dim clstemplosestr,regex
        clstemplosestr = cstr(contentstr)
    set regex = new regexp
        regex.pattern = "(<iframe){1,}[^<>]*>[^\0]*(<\/iframe>){1,}"
        regex.ignorecase = true
        regex.global = true
    clstemplosestr = regex.replace(clstemplosestr,"")
    loseiframetag = clstemplosestr
    set regex = nothing
end function

function loseobjecttag(contentstr)
    dim clstemplosestr,regex
        clstemplosestr = cstr(contentstr)
    set regex = new regexp
        regex.pattern = "(<object){1,}[^<>]*>[^\0]*(<\/object>){1,}"
        regex.ignorecase = true
        regex.global = true
    clstemplosestr = regex.replace(clstemplosestr,"")
    loseobjecttag = clstemplosestr
    set regex = nothing
end function

function losespantag(contentstr)
    dim clstemplosestr,regex
        clstemplosestr = cstr(contentstr)
    set regex = new regexp
        regex.pattern = "<(\/){0,1}span[^<>]*>"
        regex.ignorecase = true
        regex.global = true
    clstemplosestr = regex.replace(clstemplosestr,"")
    losespantag = clstemplosestr
    set regex = nothing
end function

function losefonttag(contentstr)
    dim clstemplosestr,regex
        clstemplosestr = cstr(contentstr)
    set regex = new regexp
        regex.pattern = "<(\/){0,1}font[^<>]*>"
        regex.ignorecase = true
        regex.global = true
    clstemplosestr = regex.replace(clstemplosestr,"")
    losefonttag = clstemplosestr
    set regex = nothing
end function

function loseatag(contentstr)
    dim clstemplosestr,regex
        clstemplosestr = cstr(contentstr)
    set regex = new regexp
        regex.pattern = "<(\/){0,1}a[^<>]*>"
        regex.ignorecase = true
        regex.global = true
    clstemplosestr = regex.replace(clstemplosestr,"")
    loseatag = clstemplosestr
    set regex = nothing
end function

function losedivtag(contentstr)
    dim clstemplosestr,regex
        clstemplosestr = cstr(contentstr)
    set regex = new regexp
        regex.pattern = "<(\/){0,1}div[^<>]*>"
        regex.ignorecase = true
        regex.global = true
    clstemplosestr = regex.replace(clstemplosestr,"")
    losedivtag = clstemplosestr
    set regex = nothing
end function

function losestyletag(contentstr)
    dim clstemplosestr,regex
        clstemplosestr = cstr(contentstr)
    set regex = new regexp
        regex.pattern = "(<style){1,}[^<>]*>[^\0]*(<\/style>){1,}"
        regex.ignorecase = true
        regex.global = true
    clstemplosestr = regex.replace(clstemplosestr,"")
    losestyletag = clstemplosestr
    set regex = nothing
end function

function losenotetag(contentstr)
    dim clstemplosestr,regex
        clstemplosestr = cstr(contentstr)
    set regex = new regexp
        regex.pattern = "<!--\/*[^<>]*-->"
        regex.ignorecase = true
        regex.global = true
    clstemplosestr = regex.replace(clstemplosestr,"")
    losenotetag = clstemplosestr
    set regex = nothing
end function

function losetabletag(contentstr)
    dim clstemplosestr,regex
        clstemplosestr = cstr(contentstr)
    set regex = new regexp
        regex.pattern = "<(\/){0,1}table[^<>]*>"
        regex.ignorecase = true
        regex.global = true
    clstemplosestr = regex.replace(clstemplosestr,"")
    losetabletag = clstemplosestr
    set regex = nothing
end function

function losetdtag(contentstr)
    dim clstemplosestr,regex
        clstemplosestr = cstr(contentstr)
    set regex = new regexp
        regex.pattern = "<(\/){0,1}td[^<>]*>"
        regex.ignorecase = true
        regex.global = true
    clstemplosestr = regex.replace(clstemplosestr,"")
    losetdtag = clstemplosestr
    set regex = nothing
end function

function losetrtag(contentstr)
    dim clstemplosestr,regex
        clstemplosestr = cstr(contentstr)
    set regex = new regexp
        regex.pattern = "<(\/){0,1}tr[^<>]*>"
        regex.ignorecase = true
        regex.global = true
    clstemplosestr = regex.replace(clstemplosestr,"")
    losetrtag = clstemplosestr
    set regex = nothing
end function

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网