【发布时间】:2023-03-03 17:55:01
【问题描述】:
我有一个正在运行的服务,它使用发送给它的正则表达式并使用它从字符串中检索一个值。
我可以在类中创建一个主方法并调试正则表达式(?<=\\().+?(?=\\){1}),它运行良好。
但是,一旦我将其部署到 tomcat 中进行远程测试,就会出现以下异常:
Look-behind group does not have an obvious maximum length near index 19
(?<=\\().+?(?=\\){1})
^
下面是解析被调用值的函数:
private String parsePattern(String value, String pattern)
{
String ret = "";
Matcher m = Pattern.compile(pattern).matcher(value);
while (m.find())
{
ret = m.group(0);
}
return ret;
}
是什么导致它在应用程序中编译,但在 web 应用程序中不起作用?
编辑:
使用任何字符串都会失败,但当前检查的字符串是:“(Group Camp Renovation)”
从main调用时,该方法返回“Group Camp Renovation”,通过webapp调用时,抛出异常。
【问题讨论】:
-
Pattern.compile()从 main 方法运行时与相同的正则表达式完美配合。我知道这是一个运行时异常,我想知道为什么它只在某些情况下抛出。 -
我希望你没有使用
{1},这只是你真正拥有的一个坏例子 -
Pattern.compile() 将不起作用,除非我添加了 {1}
-
@MarkoTopolnik 添加了调用它的字符串。
-
上面是被传递的确切字符串。