谢谢。又有了一个难题考regex的. 不能同时通过下面两种形式的EMAIL 请改一改
[email protected] [email protected] package may.com;
import java.util.regex.*;
public class TestOne { public static void main(String[] args) {
String email = "[email protected]";
String email2 = "[email protected]";
TestOne t = new TestOne();
System.out.println(t.isMail(email));
System.out.println(t.isMail(email2));
}
private boolean isMail(String mail) {
Pattern p = Pattern.compile("\\p{Alnum}+@\\w+\\.\\p{Alnum}{2,3}[\\.\\p{Alnum}{2.3}]?");//高手改一下
Matcher m = p.matcher(mail);
String[] words = p.split(mail);
if(m.find()&&words.length==0){
return true;
}else {
return false;
}
}
}
[email protected] [email protected] package may.com;
import java.util.regex.*;
public class TestOne { public static void main(String[] args) {
String email = "[email protected]";
String email2 = "[email protected]";
TestOne t = new TestOne();
System.out.println(t.isMail(email));
System.out.println(t.isMail(email2));
}
private boolean isMail(String mail) {
Pattern p = Pattern.compile("\\p{Alnum}+@\\w+\\.\\p{Alnum}{2,3}[\\.\\p{Alnum}{2.3}]?");//高手改一下
Matcher m = p.matcher(mail);
String[] words = p.split(mail);
if(m.find()&&words.length==0){
return true;
}else {
return false;
}
}
}
这两种形式的 第2种后面多了一个.cn
???