import java.lang.String; import java.util.regex.Pattern; .. import java.util.regex.Matcher; private static void pattern(){ //电子邮件 String check = "^\\s*\\w+(?:\\.{0,1}[\\w-]+)*@[a-zA-Z0-9]+(?:[-.][a-zA-Z0-9]+)*\\.[a-zA-Z]+\\s*$"; Pattern regex = Pattern.compile(check); Matcher matcher = regex.matcher("12241@qq.name"); boolean isMatched = matcher.matches(); System.out.println(isMatched); }