首页 > Web开发 > 详细

正则表达式,提取html标签的属性值

时间:2019-01-25 12:10:12      阅读:224      评论:0      收藏:0      [点我收藏+]
 1 /**
 2      * 提取HTML标签的属性值
 3      * @param source HTML标签内容 
 4      *      "<a title=中国体育报 href=‘‘>aaa</a><a title=‘北京日报‘ href=‘‘>bbb</a>"
 5      * @param element 标签名称    a
 6      * @param attr 标签属性   title
 7      * @return
 8      */
 9     public static List<String> match(String source, String element, String attr) {
10         List<String> result = new ArrayList<String>();
11         String reg = "<" + element + "[^<>]*?\\s" + attr + "=[‘\"]?(.*?)[‘\"]?\\s.*?>";
12         Pattern pt = Pattern.compile(reg);
13         Matcher m = pt.matcher(source);
14         while (m.find()) {
15             String r = m.group(1);
16             result.add(r);
17         }
18         return result;
19     }

 

正则表达式,提取html标签的属性值

原文:https://www.cnblogs.com/guoxiangyue/p/10318827.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!