package test;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class getUrl {
/**
* 使用正则表达式提取中括号中的内容
*
* @param msg
* @return
*/
public static List<String> getImageSrc(String htmlCode) {
List<String> imageSrcList = new ArrayList<String>();
Pattern p = Pattern.compile(
"<img\\b[^>]*\\bsrc\\b\\s*=\\s*('|\")?([^'\"\n\r\f>]+(\\.jpg|\\.bmp|\\.eps|\\.gif|\\.mif|\\.miff|\\.png|\\.tif|\\.tiff|\\.svg|\\.wmf|\\.jpe|\\.jpeg|\\.dib|\\.ico|\\.tga|\\.cut|\\.pic)\\b)[^>]*>",
Pattern.CASE_INSENSITIVE);
Matcher m = p.matcher(htmlCode);
String quote = null;
String src = null;
while (m.find()) {
quote = m.group(1);
src = (quote == null || quote.trim().length() == 0) ? m.group(2).split("\\s+")[0] : m.group(2);
imageSrcList.add(src);
}
return imageSrcList;
}
/**
* 获取主机的主地址
*
* @param url
* @return
*/
public static String getFirstUrl(String url) {
return url.substring(url.indexOf("http://"), url.indexOf("/", 7));
}
}
最近下载更多
最近浏览更多
SZEPEZS LV9
2月18日
ma406805131 LV19
2024年5月25日
一本正经的胡乱叭叭叭
2024年5月20日
暂无贡献等级
朱俪的邮件及存储 LV8
2024年3月11日
admin_z LV22
2024年1月29日
ljt289917726 LV3
2023年12月18日
Pro_Guoli
2023年3月23日
暂无贡献等级
12cq345 LV6
2022年11月15日
softandroad
2022年11月8日
暂无贡献等级
heqian LV17
2022年10月17日

