Parse multiple doubles from a String

后端 未结 4 1498
轮回少年
轮回少年 2020-12-20 01:57

I would like to know how to parse several double numbers from a string, but string can be mixed, for instance: String s = \"text 3.454 sometext5.567568more_text\"

4条回答
  •  不思量自难忘°
    2020-12-20 02:52

    You could search for the following regex:

    Pattern.compile("[-+]?[0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?")
    

    and then use Double.parseDouble() on each match.

提交回复
热议问题