public class RegexDemo {
public static void main(String[] args) {
// 定義一個郵箱
String a = "1563435@qq.com";
// 使用正則表達式判斷
boolean matches = a.matches("[A-Za-z\\d]+([-_.][A-Za-z\\d]+)*@([A-Za-z\\d]+[-.])+[A-Za-z\\d]{2,4}");
// 輸出判斷結果正確為true 錯誤為false
System.out.println(matches);
}
}
