62,614
社区成员
发帖
与我相关
我的任务
分享
public static void main(String[] args) throws IOException {
String reg = "(^[A-Za-z0-9]{5,10}$)|(^[A-Za-z0-9]{4,9}(&|#|%)$)";
System.out.println("dddd11#".matches(reg));
}
&|#|%可以随意增加特殊字符,记得用|分开
public static void main(String[] args) {
String s = "aBd1#";
Matcher m = Pattern.compile("&|#|%").matcher(s);
System.out.println(!s.matches("_")?s.matches("[&#%\\w]{5,10}")?m.find()?!m.find():true:false:false);
}
public static void main(String[] args) throws IOException {
String reg = "[A-Za-z0-9]*[&|$|#]{0,1}[A-Za-z0-9]*";
if (5 <= reg.length() || reg.length() <= 10) {
System.out.println("#aaaa1a".matches(reg));
}else{
System.out.println("false");
}
}
看了下,挺复杂的,两部到位。凑合用……