有些字符串也不是富文本,也不是帶標準標籤的圖片地址和文字。想篩選出全部圖片或地址怎麼辦呢。話很少說直接上帶碼。.net
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(); } }
輸出結果:code
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/54408149blog