[英]Regular Expression which read whole number and decimal numbers ending with xx.5
how to write a regular expression so that it accepts only whole numbers and decimal ending with .5. 如何编写正则表达式,使其只接受整数和以.5结尾的十进制。 I try the following but it reads only 0.5 and whole numbers.
我尝试以下操作,但它只能读取0.5和整数。 I want it to read any number ending with '.5'.
我希望它读取以'.5'结尾的任何数字。
^0\.5|\d+$
Thanks in Advance 提前致谢
Try the following: 请尝试以下操作:
^\d+(\.5)?$
The problem with your regex is that it only matches 0 in the start of the string in case the .5
is also matched. 正则表达式的问题在于,如果
.5
也匹配,则它仅在字符串的开头匹配0。
这应该可以解决问题:
^\d+(\.5)?$
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.