Java: how to parse double from regex

前端 未结 5 418
灰色年华
灰色年华 2020-12-03 10:41

I have a string that looks like \"A=1.23;B=2.345;C=3.567\"

I am only interested in \"C=3.567\"

what i have so far is:

     Matcher m = Patter         


        
5条回答
  •  没有蜡笔的小新
    2020-12-03 11:27

    To match any sequence of digits and dots you can change the regular expression to this:

    "(?<=C=)[.\\d]+"
    

    If you want to be certain that there is only a single dot you might want to try something like this:

    "(?<=C=)\\d+(?:\\.\\d+)?"
    

    You should also be aware that this pattern can match the 1.2 in ABC=1.2.3;. You should consider if you need to improve the regular expression to correctly handle this situation.

提交回复
热议问题