Java searching float number in String

前端 未结 7 2034
轻奢々
轻奢々 2020-12-02 02:35

let\'s say i have string like that:

eXamPLestring>1.67>>ReSTOfString

my task is to extract only 1.67 from string above.

相关标签:
7条回答
  • 2020-12-02 03:30
        String s = "eXamPLestring>1.67>>ReSTOfString>>0.99>>ahgf>>.9>>>123>>>2323.12";
        Pattern p = Pattern.compile("\\d*\\.\\d+");
        Matcher m = p.matcher(s);
        while(m.find()){
            System.out.println(">> "+ m.group());
        }
    

    Gives only floats

    >> 1.67
    >> 0.99
    >> .9
    >> 2323.12
    
    0 讨论(0)
提交回复
热议问题