当两个值在 []
括号中时,为什么 String.matches
返回 true
?
System.out.println("[one]".matches("(?i).*" + "[two]" + ".*"));
//Why does it return true? Shouldn't "[]" be treated as value?
System.out.println("one".matches("(?i).*" + "two" + ".*"));//OK - prints false
System.out.println("[one]".equals("[two]"));//OK - prints false
System.out.println("one".equals("two"));//OK - prints false
最佳答案
因为 [two]
匹配字符串 "[one]"
中的字母 t、w 或 o 之一
关于java - 为什么 Java 正则表达式 ".*[two].*"匹配 "[one]"?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7431632/