publicstaticvoidmain(String[]args){
//要验证的字符串
Stringstr="service@xsoftlab.net";
//邮箱验证规则
StringregEx="[a-zA-Z_]{1,}[0-9]{0,}@(([a-zA-z0-9]-*){1,}\.){1,3}[a-zA-z\-]{1,}";
//编译正则表达式
Patternpattern=Pattern.compile(regEx);
//忽略大小写的写法
//Patternpat=Pattern.compile(regEx,Pattern.CASE_INSENSITIVE);
Matchermatcher=pattern.matcher(str);
//字符串是否与正则表达式相匹配
booleanrs=matcher.matches();
System.out.println(rs);
}