以校验邮箱为例:
public class Demo {
public static void main(String args[]) {
String str = "123456@qq.com";
//邮箱正则表达式
String pattern = "^[A-Za-z0-9\\u4e00-\\u9fa5]+@[a-zA-Z0-9_-]+(\\.[a-zA-Z0-9_-]+)+$";
boolean matches = Pattern.matches(pattern, str);
System.out.println(matches);// 控制台输出true
}
}