/** *验证电子邮件?手机号码?密码6-15位?验证输入网址?身份证号?邮编? *邮箱正则: *"[\\w]@[\\w](.\\w+)+"; */ public class StringDemo8 { public static void main(String[] args) { String email = "[email protected]"; String emailRegex = "[\\w][email protected][a-zA-z0-9]+(.\\w+)+"; String pwdRegex = "[\\w]{6,15}"; String pwd = "a_34625"; String idRegex = "[2]([\\d]{17}|[\\d]{14}|[\\d]{16}[xX])"; String id = "21010219880313212X"; String jpgImg = "mqh.jpg"; String jpgRegex = "\\."; System.out.println(email.matches(emailRegex)); System.out.println(pwd.matches(pwdRegex)); System.out.println(id.matches(idRegex)); //自动改文件名的小应用 String[] newName = jpgImg.split(jpgRegex); jpgImg = System.currentTimeMillis()+"."+newName[1]; System.out.println(jpgImg); //替换掉骂人脏话的方法的应用 String fuck = "我想说: cnm,fuck dsb"; String fuckRegex = "fuck|Sb|cnm|dsb"; fuck = fuck.replaceAll(fuckRegex, "***"); System.out.println(fuck); } }
时间: 2024-10-24 18:46:34