正则表达式匹配数字 0-99.999

Ben*_*min 1 regex

我需要一个匹配 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)

Tim*_*ker 5

^\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)