第13次作业--邮箱的正则表达式
import java.util.Scanner; public class yx { public static void main(String[] args) { Scanner reader=new Scanner(System.in); System.out.println("请输入你的邮箱:"); String yx=reader.nextLine(); String regex="[a-zA-Z0-9_.-]+@[a-zA-Z0-9-]+(\\.[a-zA-Z0-9-]+)*\\.[a-zA-Z0-9]{2,6}"; if(yx.matches(regex)){ System.out.println("您输入的邮箱格式正确"); }else{ System.out.println("您输入的邮箱格式不正确"); } } }
运行结果: