中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

Java去掉字符串中所有的標簽,獲取純文本內(nèi)容

2018-07-20    來源:open-open

容器云強勢上線!快速搭建集群,上萬Linux鏡像隨意使用
 public class Test {
 /**
  * @Title: main 
  * @Description:
  * @param args 
  * @author 
  * @date 2016年2月17日
  * 1、去掉字符串中所有的標簽,獲取純文本內(nèi)容
  * 2、獲取html節(jié)點中img的src路徑
  */
 public static void main(String[] args) {
  String html = "<div><p style='color:red;'>12132第一串字符</p></div><br /><div><p>這是第二竄字符</p></div><img width='199' src='_image/12/label'/><img width='199' src='_image/13/label'/><img width='199' src='_image/14/label'/>";
  Pattern p = Pattern.compile("<img[^>]+src\\s*=\\s*['\"]([^'\"]+)['\"][^>]*>");
  Matcher m = p.matcher(html);
  List<String> srcs = new ArrayList<String>();
        while(m.find()){
            srcs.add(m.group(1));
        }
  String regex = "<[^>]*>";
  String str = html.replaceAll(regex, "");
  System.out.println(str+"\n"+srcs.get(0));
 }
}

標簽:

版權申明:本站文章部分自網(wǎng)絡,如有侵權,請聯(lián)系:west999com@outlook.com
特別注意:本站所有轉載文章言論不代表本站觀點!
本站所提供的圖片等素材,版權歸原作者所有,如需使用,請與原作者聯(lián)系。

上一篇:Android 上拉刷新列表數(shù)據(jù)

下一篇:Android顏色轉換工具類ColorUtil