Re: different results matching regex with SDK 1.4.2

2003-12-09 Thread Oleg Sukhodolsky
>I'm not sure if it's correct or incorrect as far as the definition,
> but it would appear the "-" after the 9 isn't being treated as a
> character, but a range.

I think this is because of the bug 2121 ('.' or '-' in bracket expression
gives unexpected).

With best regards, Oleg.

-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Re: different results matching regex with SDK 1.4.2

2003-12-08 Thread Aaron Hughes
Victor,

   I'm not sure if it's correct or incorrect as far as the definition,
but it would appear the "-" after the 9 isn't being treated as a
character, but a range.

   The following seems to give your desired result.

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

  Perhaps someone more knowledgeable with regexp than myself could tell
you if it's the definition that's incorrect, or the implementation.

Cheers,
Aaron

On Mon, 2003-12-08 at 14:36, Victor Okunev wrote:
> Hi,
> 
> I am trying to verify e-mail address format using the following regular
> expression:
> 
> "^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)[EMAIL PROTECTED](\\.[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("[EMAIL PROTECTED]");
> 
> 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-]+)[EMAIL PROTECTED](\\.[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("[EMAIL PROTECTED]");
> }
> }
> 
> __ 
> Post your free ad now! http://personals.yahoo.ca
> 
> -
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
-- 
Aaron Hughes <[EMAIL PROTECTED]>
Red Rock Networks, Inc.


-
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]