独角兽企业重金招聘Python工程师标准>>>
/***提取字符串内所有的img标签下的src*@paramcontent*@return*/publicstaticList<String>getImg(Stringcontent){Stringregex;List<String>list=newArrayList<String>();//提取字符串中的img标签regex="<img[^>]+src\\s*=\\s*['\"]([^'\"]+)['\"][^>]*>";Patternpa=pile(regex,Pattern.DOTALL);Matcherma=pa.matcher(content);while(ma.find()){//提取字符串中的src路径Matcherm=pile("src=\"?(.*?)(\"|>|\\s+)").matcher(ma.group());while(m.find()){if("http".equals(m.group(1).substring(0,4))){//只提取http开头的图片地址//System.out.println(m.group(1));list.add(m.group(1));}}}returnlist;}