用正则表达式匹配字符串 要求 1.字符串只能有数字和字母,2,长度不能小于8。3,至少有两个数字。   求大神给出正则表达式

解决方案 »

  1.   


    public class Test{
    public static void main(String[] args){
    String content = "dfdafdsa13dfd";
    String regex = "^(?=.*?\\d.*?\\d)\\w{8,}$";
    System.out.println(content.matches(regex));
    }
    }
      

  2.   

    (?=[0-9a-zA-Z]*[0-9][0-9a-zA-Z]*[0-9][0-9a-zA-Z]*)[0-9a-zA-Z]{8,}
      

  3.   

    在线正则表达式
    这个网址可以在线测试正则\d{2,}(\d|[a-zA-Z]){6,}   //数字在前
    (\d|[a-zA-Z]){6,}\d{2,}   //在后
    (\d|[a-zA-Z]){2,}\d(\d|[a-zA-Z]){2,}\d(\d|[a-zA-Z]){2,}   //数字在3,6位,其他位可能为数字看看正则语法,自己会了就能满足各种需求