package seday02;
/**
* boolean matches(String regex)
* 使用給定正則表達式判斷當前字符串是否滿足格式要求,滿足 則返回true.
* 注意:此方法是做完全匹配驗證,無論是否添加正則表達式中的邊界匹配符"^...$"都是做全匹配驗證
* @author xingsir
*/
public class MatchesDemo {
public static void main(String[] args) {
String email="xingsir@sina.com";//郵箱地址
String regex="[a-zA-Z0-9_]+@[[a-zA-Z0-9]+(\\.[a-zA-Z]+)+]"; //正則表達式
boolean check=email.matches(regex);//判斷
if(check) {
System.out.println("是正確郵箱");}
else {
System.out.println("不是正確郵箱");
}
}
}