您的位置:首页 > 编程语言 > Java开发

用java 滤文本中的HTML标签(简单)

2008-05-05 17:03 585 查看
/*
* 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));
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: