當前位置:首頁 > 建站常識 > 列表

asp 正則表達式清除表格屬性

點擊:時(shí)間:2017/11/24關鍵詞:上海網站設計 asp正則表達式
'用(yòng)法 RHtml=SimpleHTML(html,"p,img,a,span")Function SimpleHTML(content,tags) If tags="" Then tags="p,br" SimpleHTML = RegReplace("&l

'用(yòng)法 RHtml=SimpleHTML(html,"p,img,a,span")

Function SimpleHTML(content,tags)

   If tags="" Then tags="p,br"

   SimpleHTML = RegReplace("<(\/?)("& Replace(tags,",","|") &")([^>]*)>",content&"","[$1$2$3]")

   SimpleHTML = RegReplace("<[^>]*>",SimpleHTML,"")

   SimpleHTML = RegReplace("\[(\/?)("& Replace(tags,",","|") &")([^\]]*)\]",SimpleHTML,"<$1$2$3>")

End Function

'生成一個(gè)正則表達式對(duì)象

Function REObject( reg, m)

   Dim re:Set re=new RegExp

   re.Pattern = reg

   If InStr(1, m, "g", 1)>0 Then re.Global = True

   If InStr(1, m, "i", 1)>0 Then re.IgnoreCase = True

   If InStr(1, m, "m", 1)>0 Then re.MultiLine = True

   Set REObject=re

End Function

Function RegReplace( reg, str, rstr)

   RegReplace=RegExpReplace(reg,"ig",str,rstr)

End Function

'正則替換字符串

Function RegExpReplace( reg, m, str, rstr)

   RegExpReplace=REObject(reg, m).Replace(str,rstr)

End Function

後面幾個(gè)是用(yòng)到的(de)函數

會将html代碼中非指定的(de)标簽全部去除,如果要去除标簽内的(de)屬性,需要修改下(xià)simplehtml這(zhè)個(gè)函數,把$3去掉

Function SimpleHTML(content,tags)

   If tags="" Then tags="p,br"

   SimpleHTML = RegReplace("<(\/?)("& Replace(tags,",","|") &")([^>]*)>",content&"","[$1$2$3]")

   SimpleHTML = RegReplace("<[^>]*>",SimpleHTML,"")

   SimpleHTML = RegReplace("\[(\/?)("& Replace(tags,",","|") &")([^\]]*)\]",SimpleHTML,"<$1$2>")

End Function


預約建站
免費提供網站優化(huà)
領取關鍵詞