[英]Regular expression which accepts 0.5 and whole numbers
Hi I need help on a regular expression which accepts only 0.5 and whole numbers. 嗨,我需要一个仅接受0.5和整数的正则表达式。 I try this but its not working: pattern="^[0.5][0-9]*"
我尝试了一下,但是没有用:pattern =“ ^ [0.5] [0-9] *”
Can someone help me? 有人能帮我吗? Thanks
谢谢
Something like the following: ^0\\.5|\\d+$
. 类似于以下内容:
^0\\.5|\\d+$
。 Just pay attention that in Java code you have to write duplicate back slashes, ie Pattern.compile("0\\\\.5|\\\\d+$")
. 请注意,在Java代码中,您必须编写重复的反斜杠,即
Pattern.compile("0\\\\.5|\\\\d+$")
。
Back slash before .
反斜杠之前
.
is required to make regex to understand that it is the character .
必须使正则表达式理解它是字符
.
and not "any character" 而不是“任何字符”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.