转 totodo(土豆仙)
import java.util.regex.*;
public class TestRegex{
public static void main(String agrs[]){
String input ="[email protected]";
Pattern p = Pattern.compile("^[\\w-.]+@([\\w-]+.)+[\\w-]{2,4}$");
Matcher m = p.matcher(input);
boolean b = m.matches();
System.out.println(b);
}
}
import java.util.regex.*;
public class TestRegex{
public static void main(String agrs[]){
String input ="[email protected]";
Pattern p = Pattern.compile("^[\\w-.]+@([\\w-]+.)+[\\w-]{2,4}$");
Matcher m = p.matcher(input);
boolean b = m.matches();
System.out.println(b);
}
}
这个email地址字符串,要包含"@",并且不以“@“开头和结尾呀。还有其它要求吗?
public class test {
public static void main(String args[] ) {
String REGEX = "^[^@]([a-zA-Z_0-9.])+@([a-zA-Z_0-9.])+[^@]$";
String strTmp = "[email protected]";
System.out.println("******" + strTmp.matches(REGEX));
}
}
请到 http://javagarden.yeah.net用正则表达式工具进行测试
[a-zA-Z0-9_\-]+@[a-zA-Z0-9_\-]+\.[a-zA-Z0-9_\-.]+
因此还是qm0445(海狗) 得完整一些,
^[\\w-.]+@[\\w-.]+[\\w]+$
必须以字母开头,后接数字,"-","_"和".",但不能有两个连续的".."或"--"吧?(能不能出现两次"a.b.c"尚未可知)
然后接"@"
"@"后是标准的域名如"sohu.com","sina.com.cn","163.com"本人对正则表达式也只是略知一二,哪位高手可给个完善的正则表达式?