I have the below code.
String testdata = "%%%variable1%%% is not equal to %%%variable2%%%"; Pattern p = Pattern.compile("\\%%%(.*?)\\%%%"); Matcher m = p.matcher(testdata); String variables = ""; int i = 0; while (m.find()) { System.out.println(m.group()); variables=m.group().replaceAll("%%%", ""); System.out.println(variables); i++; } I am trying to print the string inside two %%%. So I am expecting below output:
%%%variable1%%% variable1 %%%variable2%%% variable2 But the actual output is:
%%%variable1%%% variable1 variable2 variable2 Why is it so? What is the problem with this?
i++and usegroup(0)?