获取img标签中的src地址

import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/**
 *   @description 截取字符串中的img标签中的src地址
 *   @createTime 创建时间:2019-12-02
 */
public class GetImgSrc {
	
	public static List getImgSrc(String htmlStr) {
		if( htmlStr == null ){
			return null;
		}
		String img = "";  
        Pattern p_image;  
        Matcher m_image;  
        List pics = new ArrayList();
        String regEx_img = "]*?>";  
        p_image = Pattern.compile(regEx_img, Pattern.CASE_INSENSITIVE);  
        m_image = p_image.matcher(htmlStr);  
        while (m_image.find()) {  
            img = m_image.group();  
            Matcher m = Pattern.compile(" src\\s*=\\s*\"?(.*?)(\"|>|\\s+)").matcher(img);
            while (m.find()) {
                pics.add(m.group(1));
            }
        }
        return pics;
	}
}

你可能感兴趣的:(java)