// 要驗證的字符串
String str = "[email protected]";
// 郵箱驗證規則
String regEx = "[a-zA-Z_]{1,}[0-9]{0,}@(([a-zA-z0-9]-*){1,}\\.){1,3}[a-zA-z\\-]{1,}";
// 編譯正則表達式
Pattern pattern = Pattern.compile(regEx);
// 忽略大小寫的寫法
// Pattern pat = Pattern.compile(regEx, Pattern.CASE_INSENSITIVE);
Matcher matcher = pattern.matcher(str);
// 字符串是否與正則表達式相匹配
boolean rs = matcher.matches();