private SpuChannelDescVO dealContent(SkuContentInfoVO skuchannelDesc,Integer spuId){
SpuChannelDescVO spuChannelDesc=new SpuChannelDescVO();
BeanUtils.copyProperties(skuchannelDesc,spuChannelDesc);
List<SpuResourceVO> spuResourceVOList=new ArrayList<>();
Pattern p_image;
Matcher m_image;
String img;
String regEx_img = "<img.*src\\s*=\\s*(.*?)[^>]*?>";
p_image = Pattern.compile
(regEx_img, Pattern.CASE_INSENSITIVE);
m_image = p_image.matcher(spuChannelDesc.getChannelDesc());
while (m_image.find()) {
// 得到<img />数据
img = m_image.group();
// 匹配<img>中的src数据
Matcher m = Pattern.compile("src\\s*=\\s*\"?(.*?)(\"|>|\\s+)").matcher(img);
while (m.find()) {
SpuResourceVO vo=SpuResourceVO
.builder()
.intraNetUrl(m.group(1))
.spuId(spuId)
.resourceType(ResourceTypeEnum.CONTENT.getValueString())
.sort(-1)
.build();
spuResourceVOList.add(vo);
}
}
for(int i=0;i<spuResourceVOList.size();i++){
spuResourceVOList.get(i).setSort(i);
}
spuChannelDesc.setContentResourceList(spuResourceVOList);
return spuChannelDesc;
}
正则:获取字符串中img标签内src图片地址数组
于 2022-01-21 09:28:21 首次发布