请大家写出满足如下要求的正则表达式

tteesstt 2008-07-15 10:23:44
使用正则表达式,以实现下面的功能:
1)不可以为空
2)允许含有特殊字符:! $ % & \ () - / ; < ? [] ^ {}
3)必须同时含有半角英文大写字母、半角英文小写字母以及半角数字
4)8文字以上,16文字以下


...全文
352 36 打赏 收藏 转发到动态 举报
写回复
用AI写文章
36 条回复
切换为时间正序
请发表友善的回复…
发表回复
fulton_xc 2008-09-04
  • 打赏
  • 举报
回复
学习
lonelyscud 2008-09-03
  • 打赏
  • 举报
回复
新手学习,楼上的都好复杂。。。

新手刚刚学习,只能支持下解答的各位哥哥姐姐了。
gauppo 2008-09-03
  • 打赏
  • 举报
回复
learning
shadowlin 2008-07-16
  • 打赏
  • 举报
回复
用一个正则判断出来么?还是可以分步来判断呢?
tteesstt 2008-07-16
  • 打赏
  • 举报
回复
请 火龙果 到 http://topic.csdn.net/u/20080716/22/80cdd418-a0e9-4e7e-8435-df6d4bc11c4a.html

给解释一下您的正则好吗?

拜托了!!!
power_115 2008-07-16
  • 打赏
  • 举报
回复
xuexi
chenyanpan 2008-07-16
  • 打赏
  • 举报
回复
我发现老紫竹很厉害!!
chenyanpan 2008-07-16
  • 打赏
  • 举报
回复
正则表达式,不懂,但还是回复一下
jdlsfl 2008-07-16
  • 打赏
  • 举报
回复
joejoe1991 强人
lisl2003 2008-07-16
  • 打赏
  • 举报
回复
拜一下上面给出代码的哥哥们
  • 打赏
  • 举报
回复
嗯,接受鄙视,自已进小黑屋去……
joejoe1991 2008-07-16
  • 打赏
  • 举报
回复
false
false
false
true
true
false
false
false
true
true
joejoe1991 2008-07-16
  • 打赏
  • 举报
回复
这下应该没问题了.

    public static void main(String[] args) {
System.out.println(regexText(""));
System.out.println(regexText("123"));
System.out.println(regexText("A4783"));
System.out.println(regexText("zA25$4783"));
System.out.println(regexText("z4uu3j57E{"));
System.out.println(regexText("524754x1&#"));
System.out.println(regexText("10248Zgk@"));
System.out.println(regexText("102xfas44dsfdhd48Zgk@"));
System.out.println(regexText("xfAs!dsf5dh&doo"));
System.out.println(regexText("xfAsmdsf5dhdoo"));

}

public static boolean regexText(String value) {
return value.matches("^(?=.*\\p{Lower})(?=.*\\p{Upper})(?=.*\\p{Digit})(.((?<!\\p{Punct})|(?<=[-!$%&()/;<?{}\\[\\]\\\\^]))){8,16}$");
}
  • 打赏
  • 举报
回复
public class T {
public static void main(String[] args) {
System.out.println(regexText("13a4C5fdsfiaf"));
System.out.println(regexText("123"));
System.out.println(regexText("A47c83"));
System.out.println(regexText("ZA25$4783"));
System.out.println(regexText("z457E{"));
System.out.println(regexText("524754x1&#"));
System.out.println(regexText("10248Zgk@"));
System.out.println(regexText("102xfas44dsfdhd48Zgk@"));
}

public static boolean regexText(String value) {
String all = "[\\p{Graph}]{0,}";
StringBuilder b = new StringBuilder();
b.append("(" + all + "[0-9]+" + all + "[a-z]+" + all + "[A-Z]+" + all + ")");
b.append("|");
b.append("(" + all + "[0-9]+" + all + "[A-Z]+" + all + "[a-z]+" + all + ")");
b.append("|");
b.append("(" + all + "[a-z]+" + all + "[0-9]+" + all + "[A-Z]+" + all + ")");
b.append("|");
b.append("(" + all + "[a-z]+" + all + "[A-Z]+" + all + "[0-9]+" + all + ")");
b.append("|");
b.append("(" + all + "[A-Z]+" + all + "[a-z]+" + all + "[0-9]+" + all + ")");
b.append("|");
b.append("(" + all + "[A-Z]+" + all + "[0-9]+" + all + "[a-z]+" + all + ")");
return value.matches(b.toString()) && value.matches("[\\p{Graph}]{8,16}");
}
}



:! $ % & \ () - / ; < ? [] ^ {}
jyq0105 2008-07-16
  • 打赏
  • 举报
回复
"^(?=.*\\p{Punct})(?=.*\\p{Lower})(?=.*\\p{Upper})(?=.*\\p{Digit}).{8,16}$"
jishu_vip 2008-07-16
  • 打赏
  • 举报
回复
mark
joejoe1991 2008-07-16
  • 打赏
  • 举报
回复
晕,又看错了...

2)允许含有特殊字符:! $ % & \ () - / ; < ? [] ^ {}

看成必须了..
xuejelly 2008-07-16
  • 打赏
  • 举报
回复
mark
joejoe1991 2008-07-16
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 tteesstt 的回复:]
请注意需求的第三条
必须有大写,小写字母和数字,是同时含有。
[/Quote]

不好意思,忽略了"同时"了. 下面这样行不行?

    public static void main(String[] args) {
System.out.println(regexText(""));
System.out.println(regexText("123"));
System.out.println(regexText("A4783"));
System.out.println(regexText("zA25$4783"));
System.out.println(regexText("z457E{"));
System.out.println(regexText("524754x1&#"));
System.out.println(regexText("10248Zgk@"));
System.out.println(regexText("102xfas44dsfdhd48Zgk@"));
System.out.println(regexText("xfAs.!.dsf5dhdoo"));
}

public static boolean regexText(String value) {
return value.matches("^(?=.*\\p{Punct})(?=.*\\p{Lower})(?=.*\\p{Upper})(?=.*\\p{Digit}).{8,16}$");
}
tteesstt 2008-07-16
  • 打赏
  • 举报
回复
请注意需求的第三条
必须有大写,小写字母和数字,是同时含有。
加载更多回复(15)

62,614

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧