package com.lovo.test;
class Test01 {
public static void main(String[] args) {
String username = "xyz_admin123xyz";
// 通过Pattern类的静态方法compile创建正则表达式对象
// Pattern p = Pattern.compile("[a-zA-Z]\\w{5,19}");
//
// if(p.matcher(username).matches()) {
// System.out.println("合法用户名!");
// }
// else {
// System.out.println("非法用户名!");
// }
if(username.matches("^[a-zA-Z]\\w{5,19}$")) {
System.out.println("合法");
}
else {
System.out.println("非法");
}
}
}
正则表达式
最新推荐文章于 2024-05-20 10:35:51 发布