简体   繁体   English

为什么Java中的转义点Regex与输入字符串不匹配

[英]Why escaped dot Regex in Java doesn't match a entry string

I'm trying to check if a string matches a regex of a double type value in Java. 我正在尝试检查字符串是否匹配Java中双精度类型值的正则表达式。

I want to understand why the following instruction prints "false". 我想了解为什么以下指令显示“ false”。

System.out.println("1.".matches("1\\."));

And why this prints "false" 以及为什么打印“ false”

System.out.println("1.2".matches("[1-9][0-9]*(\\.[0-9]*)?"));

And why this prints "true" 以及为什么打印出“ true”

System.out.println("1.2a".matches("-?\\d+(\\.\\d+)?"));

Double \\matches方法的regex参数转义点字符

System.out.println("1.".matches("1\\."));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM