1.去掉HTML标签:
/** * 去掉HTML外面的标签 * @author CY * */public class TrimHTML { public static void main(String[] args) { String d3 = " "; String result = d3.replaceAll("<[^<>]+>", ""); System.out.println(result); }}
打印如下:
博客园 首页 新随笔 联系 订阅 管理
方法二:(参考博客:)
public class TrimHTML2 { public static void main(String[] args) { String d3 = " 我是尾巴"; Pattern p = Pattern.compile("<([^>]*)>", Pattern.CASE_INSENSITIVE); Matcher m = p.matcher(d3); StringBuffer sb = new StringBuffer(); while(m.find()){ m.appendReplacement(sb, ""); } m.appendTail(sb); System.out.println(sb.toString()); }}
打印:
博客园 首页 新随笔 联系 订阅 管理我是尾巴
------