**比如截取这段中的
版本号:3.74.1.6**
有没有什么简单的方法?indexOf这些方法对如此多的字也相形见绌。
<div class="home-top">
<div class="home-top1">
<div class="logo_cont">
<a class="logo_img" href="//pvp.qq.com/m/index.shtml">
a>
<div class="logo_title">
<h1>王者荣耀h1>
<p>团队成就更多p>
div>
div>
<div class="download">
<a class="mct_download_btn" id="downloadBtn" href="//pvp.qq.com/zlkdatasys/mct/d/play.shtml" onclick="PTTSendClick('mainnav','download','下载游戏');">
a>
div>
div>
<div class="home-top2">
<p>版本号:3.74.1.6p>
<p>更新时间:2022-06-23p>
<p>开发者:Tencent mobile Gamesp>
<div class="home-top2__links">
<p>应用涉及权限:<a href="https://pvp.qq.com/m/m201706/news.html?tid=516913">查看详情>>a>p>
<p>App隐私权限:<a href="https://game.qq.com/tencent_other_contract.shtml">查看详情>>a>p>
div>
div>
div>
使用正则匹配,参考代码如下:
public static void main(String[] args) {
String str = "<div class=\"home-top2\">\n" +
" <p>版本号:3.74.1.6</p>\n" +
" <p>更新时间:2022-06-23</p>\n" +
" <p>开发者:Tencent mobile Games</p>\n" +
" <div class=\"home-top2__links\">\n" +
" <p>应用涉及权限:<a href=\"https://pvp.qq.com/m/m201706/news.html?tid=516913\">查看详情>></a></p>\n" +
" <p>App隐私权限:<a href=\"https://game.qq.com/tencent_other_contract.shtml\">查看详情>></a></p>\n" +
" </div>";
String subStr = "";
Pattern pattern = Pattern.compile("^?版本号:[0-9\\.]{2,20}</p?");
Matcher matcher = pattern.matcher(str);
if (matcher.find()) {
subStr = matcher.group();
}
System.out.println(subStr);
}
推荐jsoup库,相当好用
jsoup.org