解决方案 »

  1.   

    System.out.println("ROOT1".matches("ROOT[A-Za-z0-9]{3}"));
    System.out.println("ROOT123".matches("ROOT[A-Za-z0-9]{3}"));
    System.out.println("ROOTa".matches("ROOT[A-Za-z0-9]{3}"));
    System.out.println("ROOTabc".matches("ROOT[A-Za-z0-9]{3}"));
      

  2.   


    var reg = /ROOT[a-zA-Z0-9]{3}/;
      

  3.   

    String regex="ROOT[\\d\\w]{3}$";  试试
      

  4.   


    长度没能限制住,我输入root123344 还是可以成功的
      

  5.   

    可以的 啊。 System.out.println("ROOT123".matches("ROOT[A-Za-z0-9]{3}"));   --> true
            System.err.println("ROOT123344".matches("ROOT[A-Za-z0-9]{3}")); --> false
    一共7位吧 。
      

  6.   

    var reg = /ROOT[a-zA-Z0-9]/;
      

  7.   


    System.out.println("ROOT2dE".matches("^ROOT\\w{3}"));
      

  8.   

    Pattern pattern = Pattern.compile("root[A-Za-z0-9]?[A-Za-z0-9]?[A-Za-z0-9]?");
    Matcher matcher = pattern.matcher("rootad1");