社区
Java EE
帖子详情
求一正则表达
boy_wh520
2006-12-21 04:49:31
判断了一个字符串 必须有 数字 小写字母 大写字母 的正则那位有啊!有的话麻烦给一个参考下!
...全文
161
5
打赏
收藏
求一正则表达
判断了一个字符串 必须有 数字 小写字母 大写字母 的正则那位有啊!有的话麻烦给一个参考下!
复制链接
扫一扫
分享
转发到动态
举报
AI
作业
写回复
配置赞助广告
用AI写文章
5 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
boy_wh520
2006-12-22
打赏
举报
回复
太感谢了!
shine333
2006-12-22
打赏
举报
回复
更正一下,刚才的错了
String regex = "[\\d[^\\p{Alnum}]]*|[\\p{Lower}[^\\p{Alnum}]]*|[\\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));
// 以下几种情况楼上的没有考虑到
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));
shine333
2006-12-22
打赏
举报
回复
反过来判断
如果符合“不存在数字字母,或者只有其中一种的”就是错误的
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));
boy_wh520
2006-12-22
打赏
举报
回复
判断了一个字符串 必须有 数字 小写字母 大写字母
至少2种的组合
就是说这个字符串
数字+小写 数字+大写 小写+大写 这样的判断 正则有吗?有的话帮忙给个思路
boy_wh520
2006-12-22
打赏
举报
回复
顶一下!希望大家帮帮忙
(中小学教育)三年级下册语文园地一正稿.ppt
(中小学教育)三年级下册语文园地一正稿.ppt
驴唇马嘴的成语.docx
驴唇马嘴的成语.docx
初中文言文分类复习.doc
初中文言文分类复习.doc
江苏省沭阳县修远中学2020届高三数学9月月考试题理含解析
江苏省沭阳县修远中学2020届高三数学9月月考试题理含解析
全国通用2016版高考数学大二轮总复习增分策略第四篇第4讲数列不等式
全国通用2016版高考数学大二轮总复习增分策略第四篇第4讲数列不等式
Java EE
67,550
社区成员
225,863
社区内容
发帖
与我相关
我的任务
Java EE
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
复制链接
扫一扫
分享
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章