Here you can find the source of delHTMLTag(String htmlStr)
public static String delHTMLTag(String htmlStr)
//package com.java2s; /*//from w w w . j a v a2s . c o m * Copyright (C) 2013 WhiteCat ?? (www.thinkandroid.cn) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import java.util.regex.Matcher; import java.util.regex.Pattern; import android.util.Log; public class Main { public static String delHTMLTag(String htmlStr) { String regEx_script = "<script[^>]*?>[\\s\\S]*?<\\/script>"; // ??script??????? String regEx_style = "<style[^>]*?>[\\s\\S]*?<\\/style>"; // ??style??????? String regEx_html = "<[^>]+>"; // ??HTML????????? Log.v("htmlStr", htmlStr); try { Pattern p_script = Pattern.compile(regEx_script, Pattern.CASE_INSENSITIVE); Matcher m_script = p_script.matcher(htmlStr); htmlStr = m_script.replaceAll(""); // ??script?? Pattern p_style = Pattern.compile(regEx_style, Pattern.CASE_INSENSITIVE); Matcher m_style = p_style.matcher(htmlStr); htmlStr = m_style.replaceAll(""); // ??style?? Pattern p_html = Pattern.compile(regEx_html, Pattern.CASE_INSENSITIVE); Matcher m_html = p_html.matcher(htmlStr); htmlStr = m_html.replaceAll(""); // ??html?? } catch (Exception e) { // TODO: handle exception } return htmlStr; } }