/**
- String支持正则表达式的方法一:
- boolean matches(String regex)
- 使用给定的正则表达式匹配当前字符串是否符合格式要求,符合返回true
- 注意:给定的正则表达式就算不指定便捷通配符
- 即:(^…$)也是做完全匹配的
*/
public class MathChesDemo {
public static void main(String[] args) {
//[a-zA-Z0-9_]+@[a-zA-z0-9]+(.[a-zA-Z0-9]+)+
String email="dsfasf@asfadsfds.com";
String regex="[a-zA-Z0-9_]+@[a-zA-z0-9]+(\.[a-zA-Z0-9]+)+";
boolean match=email.matches(regex);
if(match) {
System.out.println(“是邮箱”);
}
else {
System.out.println(“不是邮箱”);
}
}
}