java過濾html標籤函式

2021-06-03 22:12:22 字數 860 閱讀 3592

public static string html2text(string inputstring)  

string regex_style = "<[\\s]*?style[^>]*?>[\\s\\s]*?<[\\s]*?\\/[\\s]*?style[\\s]*?>"; //定義style的正規表示式

string regex_html = "<[^>]+>"; //定義html標籤的正規表示式

p_script = pattern.compile(regex_script,pattern.case_insensitive);

m_script = p_script.matcher(htmlstr);

htmlstr = m_script.replaceall(""); //過濾script標籤

p_style = pattern.compile(regex_style,pattern.case_insensitive);

m_style = p_style.matcher(htmlstr);

htmlstr = m_style.replaceall(""); //過濾style標籤

p_html = pattern.compile(regex_html,pattern.case_insensitive);

m_html = p_html.matcher(htmlstr);

htmlstr = m_html.replaceall(""); //過濾html標籤

textstr = htmlstr;

}catch(exception e)

return textstr;//返回文字字串

}

Asp過濾指定html標籤函式

過濾指定html標籤 function lfilterbadhtml byval strhtml,byval strtags dim objregexp,stroutput dim arrtag,i arrtag split strtags,set objregexp new regexp stro...

過濾HTML標籤的幾個函式

去除html標記 包括html的原始碼 已經去除後的文字 public static string nohtml string htmlstring public static string striphtml string strhtml s s r n s quot 34 amp 38 lt 6...

js過濾HTML標籤

function removehtmltag str 第乙個 g 在js中正規表示式是以 開頭的,後面的 g,含義是表示全域性模式,意思是在將匹配的模式應用於整個字串,而不是在第一次匹配上之後就停止匹配了。這個分開來解釋,其中第二個字元 是乙個轉移字元,用來轉移後面的 字元的。匹配0或1個正好在它之...