Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

java.util.regex.PatternSyntaxException: Unclosed group near index XX

874376Jul 9 2011 — edited Jul 15 2011
Hi,

Just wondering if anyone has any experience with / suggestions for the following:
String s = "(\\QschoolÔ\\E)";
Pattern p = Pattern.compile(s, Pattern.CANON_EQ);
throws
Exception in thread "main" java.util.regex.PatternSyntaxException: Unclosed group near index 38
(\Qschool(?:O?\|È\|O\?)E\b)?
                                      ^
        at java.util.regex.Pattern.error(Unknown Source)
        at java.util.regex.Pattern.accept(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 main(Tester.java:153)
Take off the CANON_EQ and it works fine - it looks like CANON_EQ causes the pattern to be rewritten and it missed the '\' before the 'E', so the '\Q' group is never terminated.

If there is another character besides the high order character before the \\E, it works:
String s = "(\\QschoolÔs\\E)";
If it isn't in a group, it also works:
String s = "\\QschoolÔ\\E";
Am I overlooking something?

javac -version
javac 1.6.0_21

java -version
java version "1.6.0_21"
Java(TM) SE Runtime Environment (build 1.6.0_21-b07)
Java HotSpot(TM) 64-Bit Server VM (build 17.0-b17, mixed mode)

Thanks.
This post has been answered by sabre150 on Jul 9 2011
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 12 2011
Added on Jul 9 2011
4 comments
7,255 views