有些字符串也不是富文本,也不是带标准标签的图片地址和文字。想筛选出所有图片或地址怎么办呢。话不多说直接上带码。

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();
    }
}

输出结果:

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。
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

原博文作者:https://blog.csdn.net/qq_24919679/article/details/54408149

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄