var scriptregex = "<scr" + "ipt[^>.]*>[sS]*?</sc" + "ript>"">

利用正则表达式移除Html标签(Javascript)

80酷酷网    80kuku.com

  javascript|正则

function StripHtml(html)
...{
    html = html  || "";
    var scriptregex = "<scr" + "ipt[^>.]*>[sS]*?</sc" + "ript>";
    var scripts = new RegExp(scriptregex, "gim");
    html = html.replace(scripts, " ");

    //Stripts the <style> tags from the html
    var styleregex = "<style[^>.]*>[sS]*?</style>";
    var styles = new RegExp(styleregex , "gim");
    html = html.replace(styles, " ");

    //Strips the HTML tags from the html
    var objRegExp = new RegExp("<(.| )+?>", "gim");
    var  strOutput = html.replace(objRegExp, " ");
   
    //Replace all < and > with < and >
    strOutput = strOutput.replace(/</, "<");
    strOutput = strOutput.replace(/>/, ">");

    objRegExp = null;
    return strOutput;
}



分享到
  • 微信分享
  • 新浪微博
  • QQ好友
  • QQ空间
点击: