将HTML的一部分与正则表达式匹配

时间:2016-06-01 14:28:41

标签: android regex jsoup

我需要帮助才能匹配本网站版本部分之后的数字。 http://apk-dl.com/com.ochs.pipette/

 <div>
    <span>Version: </span> 7.01.0.669
 </div> 

我使用Jsoup获取网站并将其过滤到此标记。

Jsoup.connect("http://apk-dl.com/" + packageName)
                    .timeout(30000)
                    .userAgent("Mozilla/5.0 (Windows; U; WindowsNT 5.1; en-US; rv1.8.1.6) Gecko/20070725 Firefox/2.0.0.6")
                    .referrer("http://www.google.com")
                    .get()
                    .select("div[class=info]")
                    .last();

我可以将它专门用于Jsoup,还是有人可以帮助正则表达式来匹配它?

2 个答案:

答案 0 :(得分:1)

Version:\s<\/span>\s([0-9\.]+)

Version: matches the characters Version: literally (case sensitive)
\s match any white space character [\r\n\t\f ]
< matches the characters < literally
\/ matches the character / literally
span> matches the characters span> literally (case sensitive)
\s match any white space character [\r\n\t\f ]
1st Capturing group ([0-9\.]+)
    [0-9\.]+ match a single character present in the list below
        Quantifier: + Between one and unlimited times, as many times as possible, giving back as needed [greedy]
        0-9 a single character in the range between 0 and 9
        \. matches the character . literally

答案 1 :(得分:0)

Version:\s<\/span>\s(.*)

我使用这样的东西,因为需要匹配像这样的1.0-build1或其他有趣的变化。需要在应用程序中进行测试。