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.