boolean matches(String regex)正则表达式判断当前字符串是否满足格式要求

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("不是正确邮箱");
}
}

}

原文地址:https://www.cnblogs.com/xingsir/p/11977926.html