Retrieve long from a version string

Well – It’s not a Long – You can extract it as a string and parse it to a Double;

    Pattern p = Pattern.compile(("(\\d\\.\\d)"));
    Matcher m = p.matcher("0.1.0.2 RELEASE");
    if (m.find()){
        System.out.println(Double.parseDouble(m.group(0)));
    }

PS: Check http://regexr.com/3d9uj to practice regular expressions

Leave a Comment