You are viewing a plain text version of this content. The canonical link for it is here.
Posted to regexp-dev@jakarta.apache.org by bu...@apache.org on 2003/07/18 14:32:06 UTC

DO NOT REPLY [Bug 21706] New: - Escaping '.' character does not work in some conditions

DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=21706>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=21706

Escaping '.' character does not work in some conditions

           Summary: Escaping '.' character does not work in some conditions
           Product: Regexp
           Version: unspecified
          Platform: PC
        OS/Version: Windows NT/2K
            Status: NEW
          Severity: Major
          Priority: Other
         Component: Other
        AssignedTo: regexp-dev@jakarta.apache.org
        ReportedBy: matthieu.recouly@laposte.net


Normally escaping the dot ('.') character using a slash ('\') should make the
regular expression consider this dot as a normal character and not the regexp
equivalent for "any character".

This seems to fail in some conditions, but can be fixed by surrounding the dot
with double quotes to make it considered as a string.

I don't have time to make a lot of tests but the code below will produce the
following output with jdk1.3 and jakarta-regexp 1.2 or latest build as of July
18th 2003, in this output the test number 5 should, in fact, not fail.

You can also see that test number 1 does not fail if dot character is surrounded
with double quotes.

---- OUTPUT BEGIN ----
[1]	Checking	"john.doe@somehost.net"	against
"^(.*<)?([a-zA-Z0-9_"."\-])+@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+(>)?$"	:	true

[2]	Checking	"john-doe@somehost.net"	against
"^(.*<)?([a-zA-Z0-9_"."\-])+@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+(>)?$"	:	true

[3]	Checking	"john_doe@somehost.net"	against
"^(.*<)?([a-zA-Z0-9_"."\-])+@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+(>)?$"	:	true

[4]	Checking	"johndoe@somehost.net"	against
"^(.*<)?([a-zA-Z0-9_"."\-])+@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+(>)?$"	:	true

[5]	Checking	"john.doe@somehost.net"	against
"^(.*<)?([a-zA-Z0-9_\.\-])+@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+(>)?$"	:	false

[6]	Checking	"john-doe@somehost.net"	against
"^(.*<)?([a-zA-Z0-9_\.\-])+@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+(>)?$"	:	true

[7]	Checking	"john_doe@somehost.net"	against
"^(.*<)?([a-zA-Z0-9_\.\-])+@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+(>)?$"	:	true

[8]	Checking	"johndoe@somehost.net"	against
"^(.*<)?([a-zA-Z0-9_\.\-])+@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+(>)?$"	:	true

---- OUTPUT END ----


---- CODE BEGIN ----
package retest;

import org.apache.regexp.*;

public class retest {

  public static void main(String args[]){

    // List of email addresses to check
    String[] emailAddresses = new String[]{
	"john.doe@somehost.net",
	"john-doe@somehost.net",
	"john_doe@somehost.net",
	"johndoe@somehost.net"
    };

    // List of reg exp to use
    String[] regExp = new String[]{
	"^(.*<)?([a-zA-Z0-9_\".\"\\-])+@(([a-zA-Z0-9\\-])+\\.)+([a-zA-Z0-9]{2,4})+(>)?$",
	"^(.*<)?([a-zA-Z0-9_\\.\\-])+@(([a-zA-Z0-9\\-])+\\.)+([a-zA-Z0-9]{2,4})+(>)?$"
    };

    try{
      int testCounter = 1;
      for (int i = 0; i < regExp.length; i++) {
	RE emailRE = new RE(regExp[i]);

	for (int j = 0; j < emailAddresses.length; j++) {
	  System.out.println("["+ (testCounter++) +"]\tChecking\t\"" + emailAddresses[j] +
			     "\"\tagainst\t\"" + regExp[i] + "\"\t:\t" +
			     emailRE.match(emailAddresses[j]));
	}
      }
    }
    catch(Exception e){
      System.out.println(e);
    }
  }
}
---- CODE END ----

---------------------------------------------------------------------
To unsubscribe, e-mail: regexp-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: regexp-dev-help@jakarta.apache.org