/**
* 获取html字符串中第一张图片的路径
* @param htmlcontent
* @return
*/
public static String getImgFromHtml(String htmlcontent){
if(htmlcontent!=null){
String regEx_img = "]*?>";
Pattern p_image = Pattern.compile(regEx_img,Pattern.CASE_INSENSITIVE);
Matcher m_image = p_image.matcher(htmlcontent);
if(m_image.find()){
String img = m_image.group(0);
Matcher m = Pattern.compile("src\\s*=\\s*\"?(.*?)(\"|>|\\s+)").matcher(img);
if(m.find()){
if(m.group(0)!=null){
return m.group(0).substring(5, m.group(0).length()-1);
}
}
}
}
return "";
}
/**
* 获取html字符串中的文字内容(去掉标签)
* @param htmlcontent
* @return
*/
public static String getContentFromHtml(String htmlcontent){
if(htmlcontent!=null){
return htmlcontent.replaceAll("", "");
}
return "";
}
原文:http://www.cnblogs.com/xx-ggyy/p/4156942.html