登录/注册
JAVA知识库
好东西,老外用正则表达式写的HTML分离函数
转自:互联网
存成.asp文件,执行,你用ASPHTTP抓内容的时候用这个很爽,当然自己要改进一下了
<% OptionExplicit FunctionstripHTML(strHTML) 'Strips the HTML tags from strHTML DimobjRegExp,strOutput SetobjRegExp=NewRegexp objRegExp.IgnoreCase=True objRegExp.Global=True objRegExp.Pattern="<.+?>" 'Replace all HTML tag matches with the empty string strOutput=objRegExp.Replace(strHTML,"") 'Replace all < and > with < and > strOutput=Replace(strOutput,"<","<") strOutput=Replace(strOutput,">",">") stripHTML=strOutput'Return the value of strOutput SetobjRegExp=Nothing EndFunction %> <formmethod="post"id=form1name=form1> <b>EnteranHTMLString:</b><br> <textareaname="txtHTML"cols="50"rows="8"wrap="virtual"><%=Request("txtHTML")%></textarea> <p> <inputtype="submit"value="Strip HTML Tags!"id=submit1name=submit1> </form> <%ifLen(Request("txtHTML"))>0then%> <p><hr><p> <b><u>Viewofstring<i>withno</i>HTMLstripping:</u></b><br> <xmp> <%=Request("txtHTML")%> </xmp><p> <b><u>Viewofstring<i>with</i>HTMLstripping:</u></b><br> <pre> <%=StripHTML(Request("txtHTML"))%> </pre> <%EndIf%>