I have a service running that uses regex sent to it and uses it to retrieve a value from a string.
I can create a main method inside the class and debug the regex (?<=\\().+?(?=\\){1})
and it works perfectly.
However, as soon as I deploy it in tomcat to test remotely, I get the following exception:
Look-behind group does not have an obvious maximum length near index 19
(?<=\\().+?(?=\\){1})
^
Here is the function for parsing out a value that is being called:
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;
}
What is going on that is causing it to compile in an app, but not work in a webapp?
EDIT:
This fails with any string, but the string currently being checked is: "(Group Camp Renovation)"
When called from main
, the method returns "Group Camp Renovation", when called via webapp, it throws the exception.
The problem is - once again - quoting of strings in the Java code vs no quoting when read via some kind of input.
When you paste the string (?<=\\().+?(?=\\){1})
like this:
String s1 = "(?<=\\().+?(?=\\){1})";
System.out.println(s1);
you will get this output
(?<=\().+?(?=\){1})
and this is what the regexp parser sees.
But when the same string is read via an InputStream
(just as an example), nothing is altered:
String s1 = new BufferedReader(new InputStreamReader(System.in)).readLine();
System.out.println(s1);
will print
(?<=\\().+?(?=\\){1})
Which means, that the {1}
is attributed to the (?=\\)
part and not to the (?<=
part.