Java正则表达式的最简单应用

        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");
        }

 

posted @ 2016-03-03 20:10  morein2008  阅读(145)  评论(0编辑  收藏  举报