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!

Look-behind group does not have an obvious maximum length near index ...

807603Jan 11 2008 — edited Jan 11 2008
The following code presents two regular expressions for splitting a line at a ',' as long as it is not prefixed by an odd number of # characters.
        String line = "a####,b#,c,1,2";
        {
            String[] splitLine = line.split("(?<![^#](##){0,2147483647}#),");
            for (String s : splitLine)
            {
                System.out.println(s);
            }
        }
        {
            String[] splitLine = line.split("(?<![^#](##)*#),");
            for (String s : splitLine)
            {
                System.out.println(s);
            }
        }
The first regular expression works well but the second produces the runtime exception message
Exception in thread "main" java.util.regex.PatternSyntaxException: Look-behind group does not have an obvious maximum length near index 13
(?<![^#](##)*#),
Now I understand the error message BUT I don't understand why it should exist. In my view the first regex is semantically the same and represents a work around for the problem with the second since one seems always to be able to use {0,2147483647} instead of '*'?

What am I missing?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 8 2008
Added on Jan 11 2008
4 comments
2,065 views