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?