different results matching regex with SDK 1.4.2

Victor Okunev <[email protected]> Mon, 8 Dec 2003 17:36:56 -0500 (EST)
Newsgroups gmane.comp.jakarta.regexp.user
Message-ID <[email protected]>
Hi,

I am trying to verify e-mail address format using the following regular
expression:

"^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*$"

I am getting different results when I use SDK 1.2.4 and Apache Regexp. It seems
that the latter is less strict. For example, both statements:

new RE(regex).match(fred&[email protected]);
new RE(regex).match("fred@ac$me.org");

return true, which is not what I expect.

I am sure I am doing something wrong, but what?

Thanks,

-- Victor


------------- Code example --------------

import org.apache.regexp.*;
import junit.framework.TestCase;

public class Driver extends TestCase {

    protected String regex =
"^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9-]+)*$";

    public Driver(String name) {
        super(name);
    }

    private void assertNoMatch(String email) throws Exception {
        assertFalse("email.matches(\"" + email + "\")", email.matches(regex));
        assertFalse("new RE(regex).match(\"" + email + "\")", new
RE(regex).match(email));
    }

    private void assertMatch(String email) throws Exception {
        assertTrue("email.matches(\"" + email + "\")", email.matches(regex));
        assertTrue("new RE(regex).match(\"" + email + "\")", new
RE(regex).match(email));
    }

    public void test() throws Exception {
        assertMatch("[email protected]");
        assertNoMatch("fred [email protected]");
        assertNoMatch("fred&[email protected]");
        assertNoMatch("#[email protected]");
        assertNoMatch("fred@ac$me.org");
    }
}

______________________________________________________________________ 
Post your free ad now! http://personals.yahoo.ca