在java中用正则表达式获取div标签中的a标签的值和href

2024-12-02 13:11:44
推荐回答(2个)
回答1:

]>([\s\S]*?)(?=)

回答2:

String s2=">[^<].*?[^>]";//标题部分
String s3="href=/".*?/"";

Pattern pt2=Pattern.compile(s2);
Matcher mt2=pt2.matcher(mt.group());
Pattern pt3=Pattern.compile(s3);
Matcher mt3=pt3.matcher(mt.group());
while(mt2.find()&&mt3.find())
{
//System.out.println("标题:"+mt2.group().replaceAll(">|",""));
//System.out.println("网址:"+mt3.group().replaceAll("href=|>",""));
String t=mt2.group().replaceAll(">|","");
String u=mt3.group().replaceAll("href=|>","");
al.add(new ArticleList(t,u));