import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
* 去除字符串中的HTML标签
* @author xin
* 2010-06-13
*/
public class StrTest {
public String replaceAllHtmlTags(String content) {
Pattern p = null;
Matcher m = null;
String value = null;
// 去掉<>标签
p = Pattern.compile("(<[^>]*>)");
m = p.matcher(content);
while (m.find()) {
value = m.group(0);
content = content.replace(value, "");
}
return content;
}
public static void main(String[] args) {
String content = "<html><head>我是一个兵</head><body>来自老百姓</body></html>";
StrTest strTest = new StrTest();
String result = strTest.replaceAllHtmlTags(content);
System.out.println(result); //result:我是一个兵来自老百姓
}
}