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));
	}

}
最近下载更多
朱俪的邮件及存储  LV8 2024年3月11日
linkedwin  LV1 2021年6月30日
xbybjc  LV4 2021年6月30日
陈王子  LV12 2021年5月15日
geekcjj  LV18 2021年1月31日
146zui  LV1 2020年10月31日
王天麟  LV12 2020年9月9日
decisionx1  LV1 2020年6月2日
164317494  LV1 2020年4月14日
eeeerer  LV9 2020年4月12日
最近浏览更多
SZEPEZS  LV9 2月18日
ma406805131  LV19 2024年5月25日
暂无贡献等级
朱俪的邮件及存储  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日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友