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

html字符操作_html/css_WEB-ITnose

WBOY
Release: 2016-06-21 08:56:58
Original
1402 people have browsed it

 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)); }}
Copy after login

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template