java中正数和负数十进制的正则表达式

Abh*_*bhi 5 java regex

正负十进制值的正则表达式,以便可以使用模式和匹配器匹配字符串,以便正确实现,任何人都可以为我提供

小智 8

试试这个!我也用这种方式

"^-?[0-9]{1,12}(?:\.[0-9]{1,4})?$"
Run Code Online (Sandbox Code Playgroud)

规则:

ex: ^-?[0-9]{1,12}(?:\.[0-9]{1,4})?$
^           # Start of string
[0-9]{1,12} # Match 1-12 digits (i. e. 0-999999999999)
(?:         # Try to match...
\.          # a decimal point
[0-9]{1,4}  # followed by one to three digits (i. e. 0-9999)
)?          # ...optionally
$            # End of string
Run Code Online (Sandbox Code Playgroud)