Re: regex bug jre6???



hiwa,

Thanks for taking the time to write that up and respond. It helped me
shed a little more light on the issue. It's not the "\\" that causes
the problem, but rather "\\Q". I've modified RegX and regex.txt a bit
to highlight the problem. Runtime output is from 1.4, 1.5, and 1.6
(with the Exception pasted in).

/** content of regex.txt **
^((VINCENT)|(GEORGIA)|(GIACOMO\\QUARENGHI)|(CLAUDE))$[newline]
***************************/

import java.io.*;
import java.util.regex.*;

public class RegX
{
public static void main(String[] args)
{
System.out.print("\nJava Version " +
System.getProperty("java.specification.version"));
System.out.println("\n----------------");
String regex = null;
String text = "GEORGIA";

try
{
BufferedReader br
= new BufferedReader(new FileReader("regex.txt"));
regex = br.readLine();
}
catch (Exception e)
{
e.printStackTrace();
}

Pattern pat = Pattern.compile(regex);
Matcher mat = pat.matcher(text);

System.out.println("\nLooking for \"" + text + "\" in \"" +
regex + "\"");
while (mat.find())
{
System.out.println("\t--> " + mat.group());
}

System.out.print("\n\"" + text + "\" matches \"" +
regex + "\"... ");
System.out.println(text.matches(regex));
System.out.println

("\n====================================================\n");
}
}


OUTPUT...

Java Version 1.4
----------------

Looking for "GEORGIA" in
"^((VINCENT)|(GEORGIA)|(GIACOMO\\QUARENGHI)|(CLAUDE))$"
--> GEORGIA

"GEORGIA" matches
"^((VINCENT)|(GEORGIA)|(GIACOMO\\QUARENGHI)|(CLAUDE))$"... true

====================================================


Java Version 1.5
----------------

Looking for "GEORGIA" in
"^((VINCENT)|(GEORGIA)|(GIACOMO\\QUARENGHI)|(CLAUDE))$"
--> GEORGIA

"GEORGIA" matches
"^((VINCENT)|(GEORGIA)|(GIACOMO\\QUARENGHI)|(CLAUDE))$"... true

====================================================


Java Version 1.6
----------------

Exception in thread "main" java.util.regex.PatternSyntaxException:
Illegal/unsupported escape squence near index 31
^((VINCENT)|(GEORGIA)|(GIACOMO\\QUARENGHI)|(CLAUDE))$
^
at java.util.regex.Pattern.error(Unknown Source)
at java.util.regex.Pattern.escape(Unknown Source)
at java.util.regex.Pattern.atom(Unknown Source)
at java.util.regex.Pattern.sequence(Unknown Source)
at java.util.regex.Pattern.expr(Unknown Source)
at java.util.regex.Pattern.group0(Unknown Source)
at java.util.regex.Pattern.sequence(Unknown Source)
at java.util.regex.Pattern.expr(Unknown Source)
at java.util.regex.Pattern.group0(Unknown Source)
at java.util.regex.Pattern.sequence(Unknown Source)
at java.util.regex.Pattern.expr(Unknown Source)
at java.util.regex.Pattern.compile(Unknown Source)
at java.util.regex.Pattern.<init>(Unknown Source)
at java.util.regex.Pattern.compile(Unknown Source)
at RegX.main(RegX.java:25)

.



Relevant Pages

  • Re: PA on AAT
    ... You're right of course, Mario, but some people get mad when they hear the ... We all know that erectus dispersed to Java, Georgia, Kenya, Algeria etc ...
    (sci.anthropology.paleo)
  • Re: "New Educational Opportunities"
    ... to indoctrinate kids to be liberals ... other place in georgia with the possible exception of savannah, ...
    (rec.sport.football.college)
  • Re: Russkie Stock Market Says Bye Bye Down The Poop-Chute
    ... US bankruptcy. ... Brazil is no exception, so clearly Georgia has nothing ...
    (soc.culture.baltics)
  • Re: Correct me if Im wrong
    ... When someone says "the exception proves the rule" they're using an ... Proving Ground, and so on. ... English major at the University of Georgia to understand. ...
    (rec.sport.football.college)