首页  >  文章  >  web前端  >  html字符操作_html/css_WEB-ITnose

html字符操作_html/css_WEB-ITnose

WBOY
WBOY原创
2016-06-21 08:56:581355浏览

 public class Test { /**  * @Title: main   * @Description:  * @param args   * @author   * @date 2016年2月17日  * 1、去掉字符串中所有的标签,获取纯文本内容  * 2、获取html节点中img的src路径  */ public static void main(String[] args) {  String html = "<div><p style='color:red;'>12132第一串字符</p></div><br /><div><p>这是第二窜字符</p></div><img     style="max-width:90%" src='_image/12/label'/ alt="html字符操作_html/css_WEB-ITnose" ><img     style="max-width:90%" src='_image/13/label'/ alt="html字符操作_html/css_WEB-ITnose" ><img     style="max-width:90%" src='_image/14/label'/ alt="html字符操作_html/css_WEB-ITnose" >";  Pattern p = Pattern.compile("<img [^ alt="html字符操作_html/css_WEB-ITnose" >]+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)); }}

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn