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

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

/**  输入邮箱,利用正则表达式,判断输入的字符串是否为邮箱  */

import java.util.Scanner;

public class Test {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入您的邮箱:");
        String s = sc.nextLine();
        String regex = "\\w{0,}+[@]\\w+[.]\\w+";
        if(s.matches(regex))
            System.out.println("邮箱输入正确");        
        else
            System.out.println("邮箱输入错误,请重新输入");
    }

}

运行截图:

 

 

 

posted @ 2019-11-24 17:10  季英杰  阅读(131)  评论(0编辑  收藏  举报