如果包含 " ! @ # $ % ^ & * " 中的任何一个或多个则返回true,否则返回false。
请教了,最好有源码,谢谢

解决方案 »

  1.   


        public static boolean regex()
        {
            String str = " ! @ # $ % ^ & * ";
            Pattern p = Pattern.compile("!+|@+|#+|\\$+|%+|\\^+|&+|\\*+");
            Matcher m = p.matcher(str);
            while (m.find())
            {
                return true;
            }
            return false;    }
      

  2.   


    String fileName = "!#@.xml";
    String regex = "[!@#\\&%\\^&\\*]*";
    Pattern p = Pattern.compile(regex);
    Matcher m = p.matcher(fileName);
    System.out.println(m.matches());fileName = "!#@.xml";时应该返回true,如果包含任意一个 " ! @ # $ % ^ & * " 就返回true
      

  3.   

    String regex = ".*[!@#\\&%\\^&\\*]+.*";
      

  4.   

    public static boolean regex()
        {
            String str = " ! @ # $ % ^ & * ";
            Pattern p = Pattern.compile("!+|@+|#+|\\$+|%+|\\^+|&+|\\*+");
            Matcher m = p.matcher(str);
            while (m.find())
            {
                return true;
            }
            return false;    }
    String fileName = "!#@.xml";
            String regex = "[!@#\\&%\\^&\\*]*";
            Pattern p = Pattern.compile(regex);
            Matcher m = p.matcher(fileName);
            System.out.println(m.matches());受用耶
      

  5.   

    yanliang_xt 已解决 谢谢啦
      

  6.   

    你看看 老鸭的 他的写的 挺好,但是 不易读,我的这个你看看api能很快读出来。。
      

  7.   

    String里有个matches()方法可以用的。