正则表达式 判断 连号如“123456”、同号如“888888”、连同号如“112233”“222333”

前端之家收集整理的这篇文章主要介绍了正则表达式 判断 连号如“123456”、同号如“888888”、连同号如“112233”“222333”前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
  1. importjava.util.regex.Matcher;
  2. importjava.util.regex.Pattern;
  3. publicclassRegu{
  4. staticvoidmain(String[]args){
  5. //匹配6位顺增
  6. Stringpattern="(?:0(?=1)|1(?=2)|2(?=3)|3(?=4)|4(?=5)|5(?=6)|6(?=7)|7(?=8)|8(?=9)){5}\\d";
  7. Patternpa=Pattern.compile(pattern);
  8. Stringmc="123456";
  9. Matcherma=pa.matcher(mc);
  10. System.out.println("6位顺增:"+ma.matches());
  11. System.out.println("*******分割线*******");
  12. //匹配6位顺降
  13. pattern="(?:9(?=8)|8(?=7)|7(?=6)|6(?=5)|5(?=4)|4(?=3)|3(?=2)|2(?=1)|1(?=0)){5}\\d";
  14. pa=Pattern.compile(pattern);
  15. mc="654321";
  16. ma=pa.matcher(mc);
  17. System.out.println("6位顺降:"+ma.matches());
  18. //匹配6位顺增或顺降
  19. pattern="(?:(?:0(?=1)|1(?=2)|2(?=3)|3(?=4)|4(?=5)|5(?=6)|6(?=7)|7(?=8)|8(?=9)){5}|(?:9(?=8)|8(?=7)|7(?=6)|6(?=5)|5(?=4)|4(?=3)|3(?=2)|2(?=1)|1(?=0)){5})\\d";
  20. mc="234567";
  21. System.out.println("6位顺增或顺降:"+ma.matches());
  22. //匹配4-9位连续的数字
  23. pattern="(?:(?:0(?=1)|1(?=2)|2(?=3)|3(?=4)|4(?=5)|5(?=6)|6(?=7)|7(?=8)|8(?=9)){3,}|(?:9(?=8)|8(?=7)|7(?=6)|6(?=5)|5(?=4)|4(?=3)|3(?=2)|2(?=1)|1(?=0)){3,})\\d";
  24. mc="123456789";
  25. System.out.println("4-9位连续的数字:"+ma.matches());
  26. //匹配3位以上的重复数字
  27. pattern="([\\d])\\1{2,}";
  28. mc="888888";
  29. System.out.println("3位以上的重复数字:"+ma.matches());
  30. //匹配手机号码类
  31. pattern="(13[0-9]|15[0-9]|18[0-9])([\\d]{2,4}){2}";
  32. mc="18930333033";
  33. System.out.println("手机号码:"+ma.matches());
  34. ////匹配连同号如“112233”“222333”
  35. //pattern="([\\d])\1{1,}([\\d])\\2{2,}";//这个测试没有通过,要重新编写
  36. //pa=Pattern.compile(pattern);
  37. //mc="33111";
  38. //ma=pa.matcher(mc);
  39. //System.out.println("连同号如112233,222333:"+ma.matches());
  40. //匹配2233类型
  41. pattern="([\\d])\\1{1,}([\\d])\\2{1,250);line-height:18px;"> mc="2233";
  42. System.out.println("2233类型:"+ma.matches());
  43. }
  44. }
原文链接:https://www.f2er.com/regex/357680.html

猜你在找的正则表达式相关文章