Java regex error - Look-behind group does not have an obvious maximum length

前端 未结 3 990
不知归路
不知归路 2020-12-05 15:10

I get this error:

java.util.regex.PatternSyntaxException: Look-behind group does not have an
    obvious maximum length near index 22
([a-z])(?!.*\\1)(?

        
3条回答
  •  情书的邮戳
    2020-12-05 15:19

    Java doesn't support variable length in look behind.
    In this case, it seems you can easily ignore it (assuming your entire input is one word):

    ([a-z])(?!.*\1)([a-z])(?!.*\2)(.)(\3)(.)(\5)
    

    Both lookbehinds do not add anything: the first asserts at least two characters where you only had one, and the second checks the second character is different from the first, which was already covered by (?!.*\1).

    Working example: http://regexr.com?2up96

提交回复
热议问题