String a = "seeeddeqs1";
Pattern com = Pattern.compile("[\\W_]");
//用法一: 判断字符串a中是否有满足非字母和数字的字符串
if(com.matcher(a).find()){
System.out.println("dddd");
};
//用法二: 判断字符串a是否符合全是数字或字母组成的字符串
String p = "\\w+";
if(Pattern.matches(p, a)){
System.out.println("eeeeeee");
}
Java正则对象Pattern的用法
最新推荐文章于 2024-06-14 15:02:13 发布