package cn.stat.p4.ipdemo; import java.util.regex.Matcher; import java.util.regex.Pattern; public class zhengze { /** * @param args */ public static void main(String[] args) { zzyouxiang(); zztihuan(); zzfind(); } //邮箱正则 private static void zzyouxiang() { String s="liuddd@163.com"; String zz="[0-9a-zA-Z_]+@[0-9a-zA-Z]+(\.[0-9a-zA-Z]{1,3})+"; boolean b=s.matches(zz); System.out.println(b); } //正则替换 private static void zztihuan() { //去掉. String s="我我我...我我我...我我要要要...要要要要学学.....学学学学什什什什什.....什么么么....么么么么"; String str=s.replaceAll("\.+",""); System.out.println(str); //去掉重复 str=str.replaceAll("(.)\1+","$1"); System.out.println(str); } //正则查找 private static void zzfind() { String ss="qws asfgf kkk,lsdk asdfafe vzcv"; String s="\b[a-z]{3}\b"; Pattern p=Pattern.compile(s); Matcher mt=p.matcher(ss); while(mt.find()) { System.out.println(mt.group()+":"+mt.start()+":"+mt.end()); } } }