这是解析HTML中图片路径的正则表达式。
//<img\b[^<>]*?\bsrc[\s\t\r\n]*=[\s\t\r\n]*[""']?[\s\t\r\n]*(?<imgUrl>[^\s\t\r\n""'<>]*)[^<>]*?/?[\s\t\r\n]*>
String rgrEpn="<img\\b[^<>]*?\\bsrc[\\s\\t\\r\\n]*=[\\s\\t\\r\\n]*[\"\"']?[\\s\\t\\r\\n]*(?<imgUrl>[^\\s\\t\\r\\n\"\"'<>]*)[^<>]*?/?[\\s\\t\\r\\n]*>";
Pattern pattern=Pattern.compile(rgrEpn);
Matcher matcher=pattern.matcher(content);
while(matcher.find()){
String ime=matcher.group();
System.out.println(ime);
}
<img\b[^<>]*?\bsrc[\s\t\r\n]*=[\s\t\r\n]*[""']?[\s\t\r\n]*(?<imgUrl>[^\s\t\r\n""'<>]*)[^<>]*?/?[\s\t\r\n]*>
^
//<img\b[^<>]*?\bsrc[\s\t\r\n]*=[\s\t\r\n]*[""']?[\s\t\r\n]*(?<imgUrl>[^\s\t\r\n""'<>]*)[^<>]*?/?[\s\t\r\n]*>
String rgrEpn="<img\\b[^<>]*?\\bsrc[\\s\\t\\r\\n]*=[\\s\\t\\r\\n]*[\"\"']?[\\s\\t\\r\\n]*(?<imgUrl>[^\\s\\t\\r\\n\"\"'<>]*)[^<>]*?/?[\\s\\t\\r\\n]*>";
Pattern pattern=Pattern.compile(rgrEpn);
Matcher matcher=pattern.matcher(content);
while(matcher.find()){
String ime=matcher.group();
System.out.println(ime);
}
<img\b[^<>]*?\bsrc[\s\t\r\n]*=[\s\t\r\n]*[""']?[\s\t\r\n]*(?<imgUrl>[^\s\t\r\n""'<>]*)[^<>]*?/?[\s\t\r\n]*>
^
<img src=\"http://images.51cto.com/files/uploadimg/20090917/150811926.jpg\"
<img src=\"http://images.51cto.com/files/uploadimg/20070420/184031793.gif\"
<img src=\"http://images.51cto.com/files/uploadimg/20070901/205733160.gif\"
<img src=\"http://images.51cto.com/files/uploadimg/20100308/115049178.gif\"
<img src=\"http://images.51cto.com/files/uploadimg/20100307/113131795.gif\"
String content = "<div class=\"m_l_list_hot\"><div class=\"m_l_list_hot1\"><a href=\"http://developer.51cto.com/art/200909/152449.htm\" title=\"C#数组基础介绍与操作详解\"><img src=\"http://images.51cto.com/files/uploadimg/20090917/150811926.jpg\" alt=\"C#数组基础介绍与操作详解\" width=\"100\" height=\"80\" border=\"0\" /></a></div><div class=\"m_l_list_hot1\"><a href=\"http://developer.51cto.com/art/200704/46251.htm\" title=\"C#实用基础教程\"><img src=\"http://images.51cto.com/files/uploadimg/20070420/184031793.gif\" alt=\"C#实用基础教程\" width=\"100\" height=\"80\" border=\"0\" /></a></div><div class=\"m_l_list_hot1\"><a href=\"http://developer.51cto.com/art/200509/4390.htm\" title=\"C#技术开发指南\"><img src=\"http://images.51cto.com/files/uploadimg/20070901/205733160.gif\" alt=\"C#技术开发指南\" width=\"100\" height=\"80\" border=\"0\" /></a></div><div class=\"m_l_list_hot1\"><a href=\"http://book.51cto.com/art/201003/187320.htm\" title=\"SQL Server 2008编程入门经典\"><img src=\"http://images.51cto.com/files/uploadimg/20100308/115049178.gif\" alt=\"SQL Server 2008编程入门经典\" width=\"100\" height=\"80\" border=\"0\" /></a></div><div class=\"m_l_list_hot1\"><a href=\"http://book.51cto.com/art/201003/187121.htm\" title=\"Web编程入门经典--HTML、XHTML和CSS(第2版)\"><img src=\"http://images.51cto.com/files/uploadimg/20100307/113131795.gif\" alt=\"Web编程入门经典--HTML、XHTML和CSS(第2版)\" width=\"100\" height=\"80\" border=\"0\" /></a></div></div>";
String rgrEpn="<img[^<>]+(src\\s*=[^<>]+)(?<=gif\"|jpg\")[^<>]+ /?\\s*>";
Pattern pattern=Pattern.compile(rgrEpn);
Matcher matcher=pattern.matcher(content);
while(matcher.find()){
String ime=matcher.group();
System.out.println(ime);
System.out.println(matcher.group(1));试了下 这样应该可以。如果有其他格式的图片,继续加在上面。