具有一个小数点的数字的正则表达式 [英] Regex expression for numbers with one decimal points

查看:994
本文介绍了具有一个小数点的数字的正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以帮助我使用最多1位小数的任何数字的正则表达式



有效数字:
10
10 2
100015 1
99 9
10 0

无效数字:
10 01
12 333
0 233
10
10 .1< space>
10 。< space>





我尝试了什么:



i尝试使用以下表达式,但它不适用于(10.,10.space,10.1space)



 \.\d\d + 

解决方案

尝试:

 ^ \\\ + \。[1-9] \d * 




允许小数点左边两个或更多,右边至少一个。

允许10.01无效。



我正在搜索小数点左边两个或更多,右边最多一个。

然后尝试:

 ^ \\\ +(\。[1-9])?



Can anyone help me with the regular expression for any number with maximum of 1 decimal point

Valid numbers: 
10
10.2
100015.1
99.9
10.0

Invalid numbers:
10.01
12.333
0.233
10.
10.1<space>
10.<space>



What I have tried:

i tried with below expression but it does not work for (10. , 10.space , 10.1space)

\.\d\d+

解决方案

Try:

^\d\d+\.[1-9]\d*



That allows two or more to the left of the decimal point, and at least one on the right.
And allows for 10.01 being invalid.

"I am searching for that allows two or more to the left of the decimal point, and max one on the right."
Then try:

^\d\d+(\.[1-9])?



这篇关于具有一个小数点的数字的正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆