import java.util.regex.*;
class fjs{
public static void main(String [] args){
String s= "cds";
Pattern pa = Pattern.compile("[^a][^b]*");
Matcher ma = pa.matcher(s);
if(ma.matches()){
System.out.println(ma.group());
}
}
}
class fjs{
public static void main(String [] args){
String s= "cds";
Pattern pa = Pattern.compile("[^a][^b]*");
Matcher ma = pa.matcher(s);
if(ma.matches()){
System.out.println(ma.group());
}
}
}
"[^a][^b]*"表示第一个不能是a且第二个不能是b,就是你说的这种情况。
class fjs{
public static void main(String [] args){
String s= "cds"; ==》String s = "cabds";
Pattern pa = Pattern.compile("[^a][^b]*");
Matcher ma = pa.matcher(s);
if(ma.matches()){
System.out.println(ma.group());
}
}
}
就不行了。我的意思是不能包含ab,不是第一是a出现。实际上a在字符串中,可以随便出现啊。
String s = "cabds";结果也是对的呀.
没有打印出东西,意思就是没有匹配呀.