/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.sense.test;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
*
* @author tenking
*/
public class Html2Text {
/**
* @param args the command line arguments
*/
public static String html2Text(String str){
Pattern pattern = Pattern.compile("<[.[^<]]*>");
Matcher matcher = pattern.matcher(str);
str = matcher.replaceAll("");
return str;
}
public static void main(String[] args) {
String s = new String();
s = "<html><head></head><body><table><tr><td>呵呵,看看HTML标签去掉没有</td></tr></table><img src=/"http:////:www.nneye.com/"/></body></html>";
System.out.println(html2Text(s));
}
}
本文介绍了一个简单的Java程序,该程序可以将HTML文档转换为纯文本,通过正则表达式匹配并移除所有HTML标签,包括图片标签。示例代码展示了如何实现这一功能,并给出了一段具体的HTML文档作为例子。
330

被折叠的 条评论
为什么被折叠?



