正则表达式提取字符串内所有的img标签下的src路径
生活随笔
收集整理的這篇文章主要介紹了
正则表达式提取字符串内所有的img标签下的src路径
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
2019獨(dú)角獸企業(yè)重金招聘Python工程師標(biāo)準(zhǔn)>>>
/***?提取字符串內(nèi)所有的img標(biāo)簽下的src*?@param?content*?@return*/ public?static?List<String>?getImg(String?content){String?regex;?????List<String>?list?=?new?ArrayList<String>();//提取字符串中的img標(biāo)簽regex?=?"<img[^>]+src\\s*=\\s*['\"]([^'\"]+)['\"][^>]*>";?????Pattern?pa?=?Pattern.compile(regex,?Pattern.DOTALL);?????Matcher?ma?=?pa.matcher(content);?????while?(ma.find())?????{??//提取字符串中的src路徑Matcher?m?=?Pattern.compile("src=\"?(.*?)(\"|>|\\s+)").matcher(ma.group());while(m.find()){if("http".equals(m.group(1).substring(0,?4))){//只提取http開頭的圖片地址//System.out.println(m.group(1));list.add(m.group(1));}}}return?list;}轉(zhuǎn)載于:https://my.oschina.net/u/1269027/blog/225149
總結(jié)
以上是生活随笔為你收集整理的正则表达式提取字符串内所有的img标签下的src路径的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 香辣虾
- 下一篇: Chmod 提升一个文件夹下所有文件(夹