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

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

代码

/**定义了判断电子邮箱的正则表达式*/

import java.util.*;
public class Test {

    public static void main(String[] args) {
        System.out.println("请输入需要判断的字符串!");
        Scanner reader= new Scanner(System.in);
        String s = reader.nextLine();
        String s1 ="\w{0,}@[a-z0-9]{0,}[.]\w{2,3}";
        if(s.matches(s1)){
            System.out.println(s+"是电子邮箱地址!");
        }
        else{
             System.out.println(s+"不是电子邮箱地址!");
        }
        
    }

}

运行截图

原文地址:https://www.cnblogs.com/shanshan3/p/11910936.html