|
**
* Deleting Html tags
*
* @ Param inputString
* @ Return
*/
Public static String htmlRemoveTag (String inputString ){
If (inputString = null)
Return null;
String htmlStr = inputString; // String containing html tags
String textStr = "";
Java. util. regex. Pattern p_script;
Java. util. regex. Matcher m_script;
Java. util. regex. Pattern p_style;
Java. util. regex. Matcher m_style;
Java. util. regex. Pattern p_html;
Java. util. regex. Matcher m_html;
Try {
// Define the regular expression {or <script [^>] *?> [\ S \ S] *? <\/Script>
String regEx_script = "<[\ s] *? Script [^>] *?> [\ S \ S] *? <[\ S] *? \/[\ S] *? Script [\ s] *?> ";
// Define the regular expression {or <style [^>] *?> [\ S \ S] *? <\/Style>
String regEx_style = "<[\ s] *? Style [^>] *?> [\ S \ S] *? <[\ S] *? \/[\ S] *? Style [\ s] *?> ";
String regEx_html = "<[^>] +>"; // defines the regular expression of the HTML tag.
P_script = Pattern. compile (regEx_script, Pattern. CASE_INSENSITIVE );
M_script = p_script.matcher (htmlStr );
HtmlStr = m_script.replaceAll (""); // filter script tags
P_style = Pattern. compile (regEx_style, Pattern. CASE_INSENSITIVE );
M_style = p_style.matcher (htmlStr );
HtmlStr = m_style.replaceAll (""); // filter style labels
P_html = Pattern. compile (regEx_html, Pattern. CASE_INSENSITIVE );
M_html = p_html.matcher (htmlStr );
HtmlStr = m_html.replaceAll (""); // filter html tags
TextStr = htmlStr;
} Catch (Exception e ){
E. printStackTrace ();
}
Return textStr; // return a text string
} |