Why test() prints 'matches' in the first statement? I thinks this regex should always print 'not matches' if \\W sign is omitted cause the first [a-z]+ takes everything till the end of string (cause \\W is omitted) and there is not characters to fit the second [a-z]+
class Test
{
    public static void main(String[] args)
    {
        test("mymail");
        test("my.mail");
        
    }
    
    public static void test(String stringToTest)
    {
        String regex = "[a-z]+\\W?[a-z]+";
        if (stringToTest.matches(regex))
        {
            System.out.println("matches");
        }
        else
        {
            System.out.println("not matches");
        }
    }
}
