Regex to find integer or decimal from a string in java in a single group?

后端 未结 3 1139
暖寄归人
暖寄归人 2021-01-05 12:31

I am trying (\\d+|\\d+\\.\\d+) on this sample string:

Oats     124   0.99        V    1.65

but it is giving me decimal number

3条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-05 12:47

    Question not entirely clear, but the first problem I see is . is a magic character in regex meaning any character. You need to escape it with as . There are lots of regex cheat sheets out there, for example JavaScript Regex Cheatsheet

    (\d+|\d+\.\d+)
    

提交回复
热议问题