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'.
^[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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.