正则表达式筛选出jpg、png的图片url

private static void reg() {
    // TODO Auto-generated method stub

    String line = "[\"http://yjj-img-main.oss-cn-hangzhou.aliyuncs.com/1440227044447Capture One Session5324.jpg\","  
    + "\"http://yjj-img-main.oss-cn-hangzhou.aliyuncs.com/1440227044463网漏肩中长上衣.png\","  
    + "\"http://yjj-img-main.oss-cn-hangzhou.aliyuncs.com/1440227044451Capture One Session5322.jpg\"," 
    + "\"http://yjj-img-main.oss-cn-hangzhou.aliyuncs.com/1440227044427Capture One Session5326.jpg\"]";

    Pattern pattern = Pattern.compile("http://(?!(\\.jpg|\\.png)).+?(\\.jpg|\\.png)");
    Matcher matcher = pattern.matcher(line);
    while (matcher.find()) {
        System.out.println(matcher.group(0));
        System.out.println();
    }
}

输出结果:

http://yjj-img-main.oss-cn-hangzhou.aliyuncs.com/1440227044447Capture One Session5324.jpg

http://yjj-img-main.oss-cn-hangzhou.aliyuncs.com/1440227044463网漏肩中长上衣.png

http://yjj-img-main.oss-cn-hangzhou.aliyuncs.com/1440227044451Capture One Session5322.jpg

http://yjj-img-main.oss-cn-hangzhou.aliyuncs.com/1440227044427Capture One Session5326.jpg

你可能感兴趣的:(正则表达式)