Home  >  Article  >  Web Front-end  >  html字符操作_html/css_WEB-ITnose

html字符操作_html/css_WEB-ITnose

WBOY
WBOYOriginal
2016-06-21 08:56:581386browse

 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)); }}

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn