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

前端 未结 4 2095
情书的邮戳
情书的邮戳 2021-01-05 03:56

I know that java regex does not support varying length look-behinds, and that the following should cause an error

(?<=(not exceeding|no((\\\\w|\\\\s)*)mor         


        
4条回答
  •  無奈伤痛
    2021-01-05 04:07

    That is indeed strange. I don't find explanation but problem seems to disappear if you change (\\w|\\s){0,30} to [\\w\\s]{0,30}

    Pattern.compile("(?<=(not exceeding|no([\\w\\s]{0,30})more than))xxxx");
    //BTW you don't need ^-----------------------------------------^ these parenthesis
    //unless you want to use match from this group later
    

提交回复
热议问题