反过来判断如果符合“不存在数字字母,或者只有其中一种的”就是错误的 String regex = "[^\\p{Alnum}]*([\\d]*|[\\p{Lower}]*|[\\p{Upper}]*)[^\\p{Alnum}]*";
// NG
System.out.println("---NG---");
System.out.println(!"abc".matches(regex));
System.out.println(!"ABC".matches(regex));
System.out.println(!"123".matches(regex));
System.out.println(!";, \t".matches(regex));
System.out.println(!";,ABC \t".matches(regex));
System.out.println(!";,abc \t".matches(regex));
System.out.println(!";,123 \t".matches(regex));
// OK
System.out.println("---OK---");
System.out.println(!"abc123".matches(regex));
System.out.println(!"ABC123".matches(regex));
System.out.println(!"abcAbc".matches(regex));
System.out.println(!";,abcABC \t".matches(regex));
System.out.println(!";,ABCabc \t".matches(regex));
System.out.println(!";,123ABC \t".matches(regex));
System.out.println(!";,123abc \t".matches(regex));
System.out.println(!";,abc123 \t".matches(regex));
System.out.println(!";,ABC123 \t".matches(regex));
System.out.println(!";,abc123ABC \t".matches(regex));
System.out.println(!";,ab12c ... A34Bc \t".matches(regex));
// NG
System.out.println("---NG---");
System.out.println(!"abc".matches(regex));
System.out.println(!"ABC".matches(regex));
System.out.println(!"123".matches(regex));
System.out.println(!";, \t".matches(regex));
System.out.println(!";,ABC \t".matches(regex));
System.out.println(!";,abc \t".matches(regex));
System.out.println(!";,123 \t".matches(regex));
// OK
System.out.println("---OK---");
System.out.println(!"abc123".matches(regex));
System.out.println(!"ABC123".matches(regex));
System.out.println(!"abcAbc".matches(regex));
System.out.println(!";,abcABC \t".matches(regex));
System.out.println(!";,ABCabc \t".matches(regex));
System.out.println(!";,123ABC \t".matches(regex));
System.out.println(!";,123abc \t".matches(regex));
System.out.println(!";,abc123 \t".matches(regex));
System.out.println(!";,ABC123 \t".matches(regex));
System.out.println(!";,abc123ABC \t".matches(regex));
System.out.println(!";,ab12c ... A34Bc \t".matches(regex));
解决方案 »
- 代理模式讨论
- jquery load()局部刷新遇到的奇怪问题!求大拿给个答案...
- 求spring security cas单点登陆和tcl目录的相关资源
- hibernate问题, HibernateUtils下怎么画波浪线的啊
- JTREE添加图片问题
- 自定义标签高手进:JSP标签类封装HttpServletRequest对象
- 不用auto_increment 在hibernate中主键生成方式是什么?native..还是什么的
- HQL语句中,如何select后面加入一个对象。如:select new String(),cat.name from Cat as cat
- jboss和tomcat整合包哪里有下,怎么在jb2005里面配置?
- j2ee 的一点疑惑
- 数据库连接很慢(100分)
- 请教JMX广播相关事项.
// NG
System.out.println("---NG---");
System.out.println(!"abc".matches(regex));
System.out.println(!"ABC".matches(regex));
System.out.println(!"123".matches(regex));
System.out.println(!";, \t".matches(regex));
System.out.println(!";,ABC \t".matches(regex));
System.out.println(!";,abc \t".matches(regex));
System.out.println(!";,123 \t".matches(regex));
// 以下几种情况楼上的没有考虑到
System.out.println(!"a b".matches(regex));
System.out.println(!"A B".matches(regex));
System.out.println(!"1 2".matches(regex));
System.out.println(!";,A;;;BC \t".matches(regex));
System.out.println(!";,a;;;bc \t".matches(regex));
System.out.println(!";,1;;;23 \t".matches(regex));
// OK
System.out.println("---OK---");
System.out.println(!"abc123".matches(regex));
System.out.println(!"ABC123".matches(regex));
System.out.println(!"abcAbc".matches(regex));
System.out.println(!";,abcABC \t".matches(regex));
System.out.println(!";,ABCabc \t".matches(regex));
System.out.println(!";,123ABC \t".matches(regex));
System.out.println(!";,123abc \t".matches(regex));
System.out.println(!";,abc123 \t".matches(regex));
System.out.println(!";,ABC123 \t".matches(regex));
System.out.println(!";,abc123ABC \t".matches(regex));
System.out.println(!";,ab12c ... A34Bc \t".matches(regex));