日期:2014-05-17 浏览次数:20857 次
List<String> imgList = new ArrayList<String>(); Pattern pattern = Pattern.compile("\"(/.*?\\.jpg)\""); Matcher matcher = pattern.matcher(str); if (matcher.find()) { imgList.add(matcher.group(1)); while (matcher.find(matcher.end())) { imgList.add(matcher.group(1)); } }
------解决方案--------------------
//供参考 import java.util.regex.Pattern; import java.util.regex.Matcher; import java.util.List; import java.util.ArrayList; import java.io.File; class Test { public static void main(String[] args) { //取名称 String str = "vvMall/mallStoreImg/122/htmlImg/7ca76e82-0270-48f8-bd79-87bf1cb1486c.jpg /><img /vvMall/mallStoreImg/122/htmlImg/81f2335e-eb5d-4a52-9a17-de04007495e6.jpg/>看看啦啦的萨<span style=background-color: rgb(255, 255, 102);>芬阿萨德安抚</span><br />"; String regex = "[\\w,-]+\\.jpg"; Pattern p = Pattern.compile(regex); Matcher m = p.matcher(str); List<String> list = new ArrayList<String>(); while(m.find()) { list.add(m.group()); } System.out.println(list); //取文件 File file = new File("d:\\1\\"); File[] files = file.listFiles(); for(File f :files) { if(f.isFile()) list.add(f.toString()); } System.out.println(list); } }
------解决方案--------------------
用js获得获得所有图片url
document.getElementsByTagName("img");