参考function test_email(strEmail) {
var myReg = /^[_a-z0-9]+@([_a-z0-9]+\.)+[a-z0-9]{2,3}$/;
if(myReg.test(strEmail)) return true;
return false;
}
var myReg = /^[_a-z0-9]+@([_a-z0-9]+\.)+[a-z0-9]{2,3}$/;
if(myReg.test(strEmail)) return true;
return false;
}
楼主可以参考一下
地址里面可能有路由,甚至可能有地址组,还有注释。
不是正则表达式能解决的问题,必须语法分析。如果用java,那就javax.mail凑合一下了。
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);
}
}
我在java里面用,刚开始我也想用那个例子来改,但是我发现里面还有一些关于ip校验的.改起来也比较麻烦.就放弃了
A typical invocation sequence is thus Pattern p = Pattern.compile("a*b");
Matcher m = p.matcher("aaaaab");
boolean b = m.matches();A matches method is defined by this class as a convenience for when a regular expression is used just once. This method compiles an expression and matches an input sequence against it in a single invocation. The statement boolean b = Pattern.matches("a*b", "aaaaab");is equivalent to the three statements above, though for repeated matches it is less efficient since it does not allow the compiled pattern to be reused. ....