Regex Matching numbers with floating point

前端 未结 5 2172
感情败类
感情败类 2020-12-17 16:55

I have this pattern:

[0-9]*\\.?[0-9]

It matches numbers but it also matches 3.5.4 as:

  1. 3.5
  2. .4

How to f

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-17 17:39

    To match a json number:

    ^[-]?(0|[1-9][0-9]*)(\.[0-9]+)?([eE][+-]?[0-9]+)?$
    

    JSON number

    Use this regex to match .123:

    ^[-]?((0|[1-9][0-9]*)(\.[0-9]+)?|\.[0-9]+)([eE][+-]?[0-9]+)?$
    

提交回复
热议问题