A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

© MoonsenHung 中级黑马   /  2015-8-23 23:31  /  216 人查看  /  1 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

  1. package cn.itheima_02;

  2. import java.util.Scanner;

  3. /*
  4. *  * 校验邮箱:xxx@yyy.zzz
  5. *
  6. * liuyi@163.com
  7. * linqingxia@126.com
  8. * yangmi@qq.com
  9. * liukaiwei@sina.com.cn
  10. * shaoyifu@yahoo.cn
  11. * hello@itcast.cn
  12. */
  13. public class RegexDemo2 {
  14.         public static void main(String[] args) {
  15.                 while (true) {
  16.                         Scanner sc = new Scanner(System.in);
  17.                         System.out.println("请输入一个邮箱:");
  18.                         String s = sc.nextLine();
  19.                         if ("over".equals(s)) {
  20.                                 break;
  21.                         }
  22.                         String regex = "\\w+@\\w{2,8}(\\.\\w{2,3})+";
  23.                         boolean flag = s.matches(regex);
  24.                         System.out.println(flag);

  25.                 }

  26.         }
  27. }
复制代码


1 个回复

倒序浏览
好复杂,果然正则表达式好用不好读
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马