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

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

 代码部分:

package edu.ccut;
import java.util.*;

public class Text2 {
    public static void main(String[] args) {
        System.out.println("输入你的邮箱地址:");
        Scanner input=new Scanner(System.in);
        String regex = "\w+[@]\w+[.]\w+";
        String s=input.next();
        if(s.matches(regex)){
            System.out.println("输入的邮箱地址合法");
        }else
            System.out.println("输入的邮箱地址不合法");
    }
}

运行结果:

原文地址:https://www.cnblogs.com/lz150520/p/11922736.html