正则表达式是对字符串操作的一种逻辑公式就是用事先定义好的一些特定字符、及这些特定字符的组合组成一个“规则字符串”这个“规则字符串”用来表达对字符串的一种过滤逻辑
预定义字符类
.任意字符
\d数字0-9
\D非数字
\s空白字符
\S非空白字符
\w单词字符
\W非单词字符
范围词
[abc]a、 b或c简单类
[^abc]任何字符除了 a、 b或c否定
[a-zA-Z]a到z或A到Z两头的字母包括在内范围
[a-z&&[^bc]]a到z 除了 b和c [ad-z] 减去
[a-z&&[^m-p]]a到z 而非m到p [a-lq-z] 减去
数量词
X?X一次或一次也没有
X*X零次或多次
X+X一次或多次
X{n}X恰好n次
X{n,}X至少n次
X{n,m}X至少n次但是不超过m次
System out println("?一次或者一次都没有"+"1"matches("\\d?"));
System out println("*零次或多次"+"1"matches("\\d*"));
System out println("+一次或多次"+"1"matches("\\d+"));
System out println("{n}恰好n次"+"1"matches("\\d{1}"));
System out println("{n,}至少n次"+"1"matches("\\d{1,}"));
System out println("{n,m}至少n次但是不超过m次"+"1"matches("\\d{1,2}"));?一次或者一次都没有t ru e
*零次或多次t ru e
+恰好n次true
{n}至少n次true
{n,}至少n次true
{n,m}至少n次但是不超过m次t ru eimportjava.util.HashSet;importjava.util.Iterator;importjava.util.Scanner;importjava.util.Set;classUser{
String Account;
String PassWord;
publicUser(String Account,StringPassWord) {this.Account = Account;this.PassWord = PassWord;
}
@Overridepublic String toString() {return"{"+this.Account+" "+this.PassWord+"}";}
}publicclass Main {static Scanner scanner = new Scanner(System.in);static Set<User>users = newHashSet<User>();publicstaticvoid main(String[ ] args) {while(true) {
Meau();
String chioce = scanner.next();if("a" .equalsIgnoreCase(chioce) ) {
System.out.println("请输入账号 ");
String Account = scanner.next();
System.out.println("请输入密码 ");
String Password = scanner.next();
Iteratorit = users.iterator() ;booleanisLogin = false;while(it.hasNext() ) {
User user = (User) it.next();if(Account.equals(user.Account)&&Password.equals(user.PassWord)) {isLogin = true;break;
}
}if(isLogin) {
System.out.println("登录成功");try {
Thread.sleep(1000);
} catch (InterruptedExceptione) {// TODO Auto-generated catch blocke.printStackTrace();
}
}else {
System.out.println("登录失败");
}
}elseif("b" .equalsIgnoreCase(chioce) ) {
System.out.println("请输入账号 ");
String Account = scanner.next();
System.out.println("请输入密码 ");
String Password = scanner.next();if(Account.matches(" [a-zA-Z]\\d{6}\\w{0,3}")&&Password.matches("\\D\\d{2,}@") ) {
System.out.println("注册成功");users.add(new User(Account, Password));
}else{
System.out.println("注册失败");
}
}elseif("show" .equals(chioce) ) {
System.out.println("当前用户有 "+users);
}else {
System.out.println("无效选项请重新输入! ");
}
}
}publicstaticvoidMeau() {
System.out.println("*************");
System.out.println("*A登录 B注册*") ;
System.out.println("*************");
}
}
//账号必须以字母开头+六位数字+最多不超过10个字
//密码要求以非字母开头+至少两位数字+以@结尾
if(Account.matches(" [a-zA-Z]\\d{6}\\w{0,3}")
&&Password.matches("\\D\\d{2,}@") )classUser{
String Account;
String PassWord;publicUser(String Account,StringPassWord) {this.Account = Account;this.PassWord = PassWord;
}
@Overridepublic String toString() {return"{"+this.Account+" "+this.PassWord+"}";}
}
因为使用了Set集合static Set<User>users = newHashSet<User>()users.add(new User(Account, Password));
在User中要重写toString方法才能将User类中的数据给输出
rfchost怎么样?rfchost是一家开办了近六年的国人主机商,一般能挺过三年的国人商家,还是值得入手的,商家主要销售VPS,机房有美国洛杉矶/堪萨斯、中国香港,三年前本站分享过他家堪萨斯机房的套餐。目前rfchost商家的洛杉矶机房还是非常不错的,采用CN2优化线路,电信双程CN2 GIA,联通去程CN2 GIA,回程AS4837,移动走自己的直连线路,目前季付套餐还是比较划算的,有需要的可...
melbicom从2015年就开始运作了,在国内也是有一定的粉丝群,站长最早是从2017年开始介绍melbicom。上一次测评melbicom是在2018年,由于期间有不少人持续关注这个品牌,而且站长貌似也听说过路由什么的有变动的迹象。为此,今天重新对莫斯科数据中心的VPS进行一次简单测评,数据仅供参考。官方网站: https://melbicom.net比特币、信用卡、PayPal、支付宝、银联...
Nocser刚刚在WHT发布了几款促销服务器,Intel Xeon X3430,8GB内存,1TB HDD,30M不限流量,月付$60.00。Nocser是一家注册于马来西亚的主机商,主要经营虚拟主机、VPS和马来西亚独立服务器业务,数据中心位于马来西亚AIMS机房,线路方面,AIMS到国内电信一般,绕日本NTT;联通和移动比较友好,联通走新加坡,移动走香港,延迟都在100左右。促销马来西亚服务器...