gpt4 book ai didi

regex - 正则表达式为正 float

转载 作者:行者123 更新时间:2023-12-03 14:32:11 25 4
gpt4 key购买 nike

例如:
10
0.1
1.23234
123.123
0.000001
1.000
.3

错误的示例:
0001.2
-12
-1.01
+2.3

编辑:标准JavaScript正则表达式。

最佳答案

在这里试试

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

看到它 here online on Regexr

如果不希望匹配空字符串,则可以将长度检查添加到正则表达式中,例如
^(?=.+)(?:[1-9]\d*|0)?(?:\.\d+)?$

正向的 (?=.+)可确保至少包含1个字符

关于regex - 正则表达式为正 float ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6029674/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com