String emailRegex = "^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$";
Pattern pat = Pattern.compile(emailRegex);
Boolean matchFlag = pat.matcher("aabcc-gedt@163.com").find();
if (matchFlag)
{
System.out.println("match");
}
else
{
System.out.println("do not match");
}
//简写
if (Pattern.compile(emailRegex).matcher("aabcc-gedt@163.com").find())
{
System.out.println("match");
}
else
{
System.out.println("do not match");
}
Java正则表达式的最简单应用
最新推荐文章于 2024-08-05 21:10:31 发布