Why does String.matches return true when two values are in [] brackets?
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
The rectangular brackets have to be quoted.
Try
"[one]".matches("(?i).*" + Pattern.quote("[two]") + ".*")instead.