package cn.lijun.demo1; public class RegexDemo { public static void main(String[] args) { //checkPhone(); checkQQ(); } //验证手机号码是否正确 public static void checkPhone(){ String phoneNum="13721827814"; boolean b=phoneNum.matches("1[0-9][\\d]{9}"); System.out.println(b); } public static void checkQQ(){ String qq="2010634510"; boolean b=qq.matches("[1-9][\\d]{4,9}"); System.out.println(b); } //邮箱 public static void checkMail(){ String email="2010634510@qq.com"; boolean b=email.matches("[\\w]+@[0-9a-z]+(\\.[a-z]+)+"); System.out.println(b); } //分离空格 public static void split_2(){ String str="19 89 12"; String[] strArr=str.split(" +"); System.out.println("数组的长度是:"+str.length()); for(int i=0;i<strArr.length;i++){ System.out.println(strArr[i]); } } public static void split_1(){ String str="2019-03-19-10-51"; //按照-对字符串进行切割 String[] strArr=str.split("-"); System.out.println("数组的长度是:"+strArr.length); for(int i=0;i<strArr.length;i++){ System.out.println(strArr[i]); } }