用正则表达式怎么验证 6为数字和字母的混合&&6位数字和字母的混合呢?&&两边都必须是字母和数字的混合 用了一种预搜索的方式但是只是向右搜索&&前的比对还是不正确!!

解决方案 »

  1.   

    ^[a-zA-Z0-9]{6}&&[a-zA-Z0-9]{6}$
    这个是匹配 前面6个字符是字母或数字,中间是 && ,后面是6个字母或数字,14位的字符串。不知道是不是你想要的
      

  2.   

    public boolean check(String str){

    if(str.length() != 6){

    }
    Pattern pattern = null;
            Matcher matcher = null;        String regex = "";
            regex = "^[([A-z]+?[\\d]+?)|([\\d]+?[A-z]+?)[A-z\\d]*?]{6}&&[([A-z]+?[\\d]+?)|([\\d]+?[A-z]+?)[A-z\\d]*?]{6}$";        pattern = Pattern.compile(regex);
            matcher = pattern.matcher(str);
            if(matcher.find()){
                System.out.println("true");
            }else{
                System.out.println("false");
            }
            
            return true;
    }
      

  3.   

    public boolean check(String str){

    if(str.length() != 6){

    }
    Pattern pattern = null;
            Matcher matcher = null;        String regex = "";
            regex = "^[([A-z]+?[\\d]+?)|([\\d]+?[A-z]+?)[A-z\\d]*?]{6}&&[([A-z]+?[\\d]+?)|([\\d]+?[A-z]+?)[A-z\\d]*?]{6}$";        pattern = Pattern.compile(regex);
            matcher = pattern.matcher(str);
            if(matcher.find()){
                return true;
            }else{
             return false;
            }
    }
      

  4.   

    public boolean check(String str){

    Pattern pattern = null;
            Matcher matcher = null;        String regex = "";
            regex = "^[([A-z]+?[\\d]+?)|([\\d]+?[A-z]+?)[A-z\\d]*?]{6}&&[([A-z]+?[\\d]+?)|([\\d]+?[A-z]+?)[A-z\\d]*?]{6}$";        pattern = Pattern.compile(regex);
            matcher = pattern.matcher(str);
            if(matcher.find()){
                return true;
            }else{
             return false;
            }
    }
      

  5.   

    String s = "ff34gb&&2ws4gn";
    System.out.println(s.matches("\\p{Alnum}{6}\\&\\&\\p{Alnum}{6}"));