Reputation: 1434
I don't understand why the output is false
in this case:
public class Enhanced {
static String[] input = {"A","B","C"};
public static void main(String[] args){
System.out.println(input[0].matches("^[RK]"));
}
}
I thought it would be true
because 'A' is neither 'R' nor 'K'.
Upvotes: 1
Views: 51
Reputation: 9452
^[RK]
^ assert position at start of the string
[RK] matches letter R and K
You probably want to try this :
[^RK]
[^RK] matches a single character other than R or K
Upvotes: 6