Java正则表达式错误 - 后瞻组没有明显的最大长度 [英] Java regex error - Look-behind group does not have an obvious maximum length

查看:95
本文介绍了Java正则表达式错误 - 后瞻组没有明显的最大长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到此错误:

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

我正在尝试匹配 COFFEE ,但不是 BOBBEE

I'm trying to match COFFEE, but not BOBBEE.

我正在使用java 1.6。

I'm using java 1.6.

推荐答案

Java没有' t支持后面的可变长度。

在这种情况下,你似乎可以轻易忽略它(假设你的整个输入是一个单词):

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)

两个lookbehinds都不添加任何东西:第一个断言至少两个字符只有你有一个,第二个检查第二个字符与第一个字符不同,已经被覆盖(?!。* \\ 1)

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).

工作示例: http://regexr.com?2up96

这篇关于Java正则表达式错误 - 后瞻组没有明显的最大长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆