急求:正则表达式 0.01到99.99之间的数字
正确数字:0.0111.009999.999.991.0错误数字:00.00.000.5....
正确数字:0.01 1 1.00 99 99.9 99.99 1.0
错误数字:0 0.0 0.00 0. 5. 展开
错误数字:0 0.0 0.00 0. 5. 展开
3个回答
展开全部
[^0]\d?$|[^0]\d?.\d{1,2}$|0.0?[^0]$
校验结果如下:
public class PatternDemo
{
public static void main(String[] args)
{
String rule = "[^0]\\d?$|[^0]\\d?.\\d{1,2}$|0.0?[^0]$";
PatternDemo demo = new PatternDemo();
System.out.println(demo.match(rule, "0.01"));//true
System.out.println(demo.match(rule, "1"));//true
System.out.println(demo.match(rule, "1.00"));//true
System.out.println(demo.match(rule, "99"));//true
System.out.println(demo.match(rule, "99.9"));//true
System.out.println(demo.match(rule, "90.9"));//true
System.out.println(demo.match(rule, "99.99"));//true
System.out.println(demo.match(rule, "0"));//false
System.out.println(demo.match(rule, "0.0"));//false
System.out.println(demo.match(rule, "0.00"));//false
System.out.println(demo.match(rule, "0."));//false
System.out.println(demo.match(rule, "5."));//false
}
public boolean match(String rule,String src)
{
Pattern pattern = Pattern
.compile(rule);
Matcher matcher = pattern.matcher(src);
return matcher.matches();
}
}
校验结果如下:
public class PatternDemo
{
public static void main(String[] args)
{
String rule = "[^0]\\d?$|[^0]\\d?.\\d{1,2}$|0.0?[^0]$";
PatternDemo demo = new PatternDemo();
System.out.println(demo.match(rule, "0.01"));//true
System.out.println(demo.match(rule, "1"));//true
System.out.println(demo.match(rule, "1.00"));//true
System.out.println(demo.match(rule, "99"));//true
System.out.println(demo.match(rule, "99.9"));//true
System.out.println(demo.match(rule, "90.9"));//true
System.out.println(demo.match(rule, "99.99"));//true
System.out.println(demo.match(rule, "0"));//false
System.out.println(demo.match(rule, "0.0"));//false
System.out.println(demo.match(rule, "0.00"));//false
System.out.println(demo.match(rule, "0."));//false
System.out.println(demo.match(rule, "5."));//false
}
public boolean match(String rule,String src)
{
Pattern pattern = Pattern
.compile(rule);
Matcher matcher = pattern.matcher(src);
return matcher.matches();
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
(?!^0[.]0$)(?!0[.]00)(?!^0$)[0-9]{1,2}([.][0-9]{1,2})?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
x<0.01
x>99.99
x>99.99
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询