2

I understand that lookbehinds in Java cannot use * and + repetitions. I've used braces to define a maximum length for the repetition of a pattern, however it still throws the following exception:

    Exception in thread "main" java.util.regex.PatternSyntaxException: 
Look-behind group does not have an obvious maximum length near index 33
    (?<!([A-Z]{0,100}\W{0,100}){0,100})[A-Z]{2,}(?!([A-Z]+\W+)+)
Orca Ninja
  • 823
  • 1
  • 15
  • 29

1 Answers1

0

You are still using a variable length match in your lookbehind, so it is invalid. As you have it written, [A-Z]{0,100} will match between zero and 100 characters, which is effectively the same as using [A-Z]*, with the upper limit of matching characters.

woemler
  • 7,089
  • 7
  • 48
  • 67
  • But error says that `Look-behind group does not have an obvious maximum length` where we know that it wont be longer than `(100+100)*100` so max length should be known now. – Pshemo Jul 02 '13 at 16:22
  • @willOEM I am with Pshemo on this one. The regex engine should be able to compute the max length from my definition of the pattern, which is why I'm bewildered. I read "[with java] you can use the question mark and the curly braces with the max parameter specified" from http://www.regular-expressions.info/lookaround.html – Orca Ninja Jul 02 '13 at 16:25
  • 1
    The `*` and `+` are still implemented in the same way as the curly bracket. Take a look at the answer here: http://stackoverflow.com/questions/1536915/regex-look-behind-without-obvious-maximum-length-in-java – woemler Jul 02 '13 at 16:50
  • Thanks! I see what you're saying now. – Orca Ninja Jul 02 '13 at 17:21