获取<img src />正则表达式
2016-06-02 16:42
337 查看
从文本中获取<img>的src路径:
// String img = "<img.*src=(.*?)[^>]*?>"; // 获取图片url
String img = "src\\s*=\\s*\"?(.*?)(\"|>|\\s+)";// 获取图片src
Matcher matcher = Pattern.compile(img).matcher(picContent.getContent());
List<String> listImgSrc = new ArrayList<String>();
while (matcher.find()) {
listImgSrc.add(matcher.group());
// String o_path = matcher.group(1);
// int num = o_path.indexOf("/", o_path.indexOf("/") + 1);
// bashpath = o_path.substring(0, num + 1);
}
// String img = "<img.*src=(.*?)[^>]*?>"; // 获取图片url
String img = "src\\s*=\\s*\"?(.*?)(\"|>|\\s+)";// 获取图片src
Matcher matcher = Pattern.compile(img).matcher(picContent.getContent());
List<String> listImgSrc = new ArrayList<String>();
while (matcher.find()) {
listImgSrc.add(matcher.group());
// String o_path = matcher.group(1);
// int num = o_path.indexOf("/", o_path.indexOf("/") + 1);
// bashpath = o_path.substring(0, num + 1);
}
相关文章推荐
- Dom4j中String 、Document 、文件类型的xml之间的相互转换
- “服务器推”技术之使用HTTP长轮询的Comet
- ProgressDialog
- 常见的PKMS问题分析
- 通过蓝牙sniffer抓BLE数据
- 乐学成语实现之二显示主界面
- Phinecos(洞庭散人) 专注于开源技术的研究与应用 TinyXML:一个优秀的C++ XML解析器
- php 打印小票模板
- 解析漏洞总结
- 新博客 lizhaowei.me
- postgresql之distinct用法
- 基本布局(固定布局)
- Active Record 基础
- HTML Button.onclick 事件汇总
- iOS开发------XML原生解析(NSXMLParser篇)
- SQLAlchemy 几种查询方式总结
- Android onTouch事件分析和传递机制
- leetcode--Longest Palindromic Substring--最长回文子串--
- 关于javascript中Object.prototype.toString 可以被改变指向的问题
- [PHP源码阅读]strtolower和strtoupper函数