用正则表达式 取出html文件中的加粗的文字和文件中的超链接

2025-04-08 09:40:49
推荐回答(2个)
回答1:


String str = "加粗字一般是在

..

中间的 超链接一般以http://...开头";
String reg1 = "(?i)]*>((?!<\\/h1>)[\\s\\S])*)<\\/h1>";
String reg2 = "(https?:\\/\\/)?([\\da-z\\.-]+)\\.([a-z\\.]{2,6})([\\/\\w\\x20\\.-]*)*\\/?";
Pattern p = Pattern.compile(reg1);// for reg2 else
Matcher m = p.matcher(str);
while(m.find()){
    System.out.println(m.group());
}

回答2:

加粗的文字 (.*)

超链接[a-zA-z]+://[^\s]*