当前位置 : 主页 > 编程语言 > c++ >

java正则表达式匹配邮箱

来源:互联网 收集:自由互联 发布时间:2021-06-30
gistfile1.txt import java.util.Scanner;import java.util.regex.Matcher;import java.util.regex.Pattern;public class Emails {public static void main(String[] args) {Scanner scan = new Scanner(System.in);String inputStr = scan.nextLine();String
gistfile1.txt
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Emails {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String inputStr = scan.nextLine();
		String mah = "^\\w+((-\\w+)|(\\.\\w+))*\\@[A-Za-z0-9]+((\\.|-)[A-Za-z0-9]+)*\\.[A-Za-z0-9]+$";
		Pattern pattern = Pattern.compile(mah);
		Matcher matcher = pattern.matcher(inputStr);
		boolean result = matcher.matches();
		System.out.println(result);
	}

}
网友评论