import java.util.regex.*;
/**
* 去除字符串中的 HTML 標(biāo)簽內(nèi)容,只保留文本內(nèi)容。
*/
public class RemoveHtmlTags {
public static void main(String[] args) {
// 原始 HTML 字符串
String html = "<p style=\"color:red;\">這是一段包含<b>加粗</b>文本的HTML內(nèi)容。</p>";
// 定義要匹配的HTML標(biāo)簽?zāi)J?/span>
Pattern pattern = Pattern.compile("<[^>]+>", Pattern.CASE_INSENSITIVE);
// 創(chuàng)建Matcher對象并進(jìn)行匹配操作
Matcher matcher = pattern.matcher(html);
// 將匹配到的HTML標(biāo)簽替換為空格或其他需要的字符
String result = matcher.replaceAll("");
System.out.println(result);
}
}
文章來源地址http://www.zghlxwxcb.cn/news/detail-829387.html
文章來源:http://www.zghlxwxcb.cn/news/detail-829387.html
到了這里,關(guān)于【代碼庫】去除字符串中的 HTML 標(biāo)簽的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!