第13次作业--邮箱的正则表达式

题目:

定义判断电子邮箱的正则表达式,判断输入的字符串是否为电子邮箱地址。

代码:

 1 package 正则表达式;
 2 /**
 3  * 利用正则表达式判断输入邮箱是否正确
 4  */
 5 import java.util.Scanner;
 6 
 7 public class Test {
 8 
 9     public static void main(String[] args) {
10         Scanner scanner = new Scanner(System.in);
11         System.out.println("输入邮箱地址:");
12         String eMail = scanner.next();
13         String regex = "\\w+[@]\\w+[.]\\w+";
14         if (eMail.matches(regex))
15             System.out.println("地址合法");
16         else
17             System.out.println("地址非法");
18     }
19 }

截图:

 

posted @ 2019-11-23 18:39  刘明康20194682  阅读(150)  评论(0编辑  收藏  举报