正则获取html中图片路经

前端之家收集整理的这篇文章主要介绍了正则获取html中图片路经前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
---------------------- ASP.Net+Android+IO开发S.Net培训、期待与您交流! ----------------------
public static List<String> getImgStr(String htmlStr) {
 
        String img = "";
        Pattern p_image;
        Matcher m_image;
        List<String> pics = new ArrayList<String>();
 
        String regEx_img = "<img.*src=(.*?)[^>]*?>"; //图片链接地址   
        p_image = Pattern.compile(regEx_img,Pattern.CASE_INSENSITIVE);
        m_image = p_image.matcher(htmlStr);
        while (m_image.find()) {
            img = img + "," + m_image.group();
            Matcher m = Pattern.compile("src=\"?(.*?)(\"|>|\\s+)").matcher(img); //匹配src
            while (m.find()) {
                pics.add(m.group(1));
            }
        }
        return pics;
    }


---------------------- ASP.Net+Android+IOS开发.Net培训、期待与您交流! ----------------------

猜你在找的正则表达式相关文章