某个字符串中嵌有很多<img src="xxxx.[jpg,bmp,png...]" >,有什么办法可以快速的把他们查找出来放在一个list中?

解决方案 »

  1.   

    楼主是想问语法吗?
    使用String类的indexOf(),substring()方法,截取jpg,bmp,png...字符串
    再使用StringTokenizer类来解析就行了
      

  2.   

    public static List<String> parser(String html, String rex) {
    List<String> l = new ArrayList<String>();
    Pattern p = Pattern.compile(rex);
    Matcher m = p.matcher(html);
    while (m.find()) { if (m.group(1)!=null){
    l.add(m.group(1));
    }
    }
    return l;
    }html 是你要解析的内容  rex是需要的截取的内容匹配正则
      

  3.   

    可以用正则表达式String s = "<img src="xxxx.[jpg,bmp,png...]" >";
    Pattern p = Pattern.compile("<img.*?>");
    Matcher m = p.matcher(s);
    while (m.find()) {
      System.out.println(m.group());
    }
      

  4.   

    假设我要取img里的src里的文件名而已,要怎么做的呢?比如:
    <img alt="" src="http://localhost:80/zhj/huangcan/document/1000/0/20111011092323_95.png" width="200" height="200" />
    只取20111011092323_95.png而已
      

  5.   

    1.通过正则表达式("src=\".*?\"")查找字符串src="http://localhost:80/zhj/huangcan/document/1000/0/20111011092323_95.png";
    2.通过String.lastIndexOf('/')和String.lastIndexOf('"')获取文件名。
      

  6.   

    Pattern p = Pattern.compile("[\\d[\\w[\\_[\\$]]]]+\\.(?:png|jpg|bmp)");后缀名有多少个就在匹配字符串的非捕获组里加多少
      

  7.   

    public static void main(String[] args) { String str = "<img alt='' src='http://localhost:80/zhj/huangcan/document/1000/0/20111011092323_95.png' width='200' height='200' />";
    String[] strs1 = str.split("/");
    String[] strs2 = strs1[strs1.length-2].split("'");
    System.out.println(strs2[0]);
    }
      

  8.   

    indexOf("<img src="xxxx.[jpg,bmp,png...]" >")