我需要一个匹配 0 到 99.999 之间数字的正则表达式(99,999 也有效)。
有效示例:
1,1
99.9
12.876
1,777
Run Code Online (Sandbox Code Playgroud)
无效示例:
9837,83
-12,24
11.1112
Run Code Online (Sandbox Code Playgroud)
^\d{1,2}(?:[.,]\d{1,3})?$
Run Code Online (Sandbox Code Playgroud)
应该做。
解释:
^ # anchor the match at the start of the string
\d{1,2} # match one or two digits
(?: # optionally match the following group:
[.,] # a . or ,
\d{1,3} # 1-3 digits
)? # end of optional group
$ # anchor the match the end of the string
Run Code Online (Sandbox Code Playgroud)