java正则表达式判断Email格式

输入:

public class JudgeEmail {

	public static void main(String[] args) {
		//定义要匹配的Email地址的正则表达式
		String regex="\\w+@\\w+(\\.\\w+)+";
		String str1="aaa@";
		String str2="[email protected]";
		String str3="[email protected]";
		String str4="[email protected]";
		if (str1.matches(regex)) 
			System.out.println("1");
		if (str2.matches(regex)) 
			System.out.println("2");
		if (str3.matches(regex)) 
			System.out.println("3");
		if (str4.matches(regex)) 
			System.out.println("4");

	}

}
输出:



你可能感兴趣的:(java)