- package cn.itheima_02;
- import java.util.Scanner;
- /*
- * * 校验邮箱:xxx@yyy.zzz
- *
- * liuyi@163.com
- * linqingxia@126.com
- * yangmi@qq.com
- * liukaiwei@sina.com.cn
- * shaoyifu@yahoo.cn
- * hello@itcast.cn
- */
- public class RegexDemo2 {
- public static void main(String[] args) {
- while (true) {
- Scanner sc = new Scanner(System.in);
- System.out.println("请输入一个邮箱:");
- String s = sc.nextLine();
- if ("over".equals(s)) {
- break;
- }
- String regex = "\\w+@\\w{2,8}(\\.\\w{2,3})+";
- boolean flag = s.matches(regex);
- System.out.println(flag);
- }
- }
- }
复制代码
|
|