I have intelliJ running with Java/REST API and having trouble removing and replacing string in a certain format.
Response string :
{"isSuccess":[{"frequency":}]}]}}{"isSuccess":[{"frequency":}]}]}}{"isSuccess":<testData>[{"frequency":<testData>}]}]}}
Expected string :
[{"frequency":}]},{"frequency":<testData>}]},{"frequency":<testData>}}]}]}}
Actual String :
[{"frequency":<testData>}]}]}}[{"frequency":<testData>}]}]}}[{"frequency":"<testData>}]}]}}
Code :
public static String getResponseString(String response){
String getIDErrorCodeString = response.split("\\[")[0];
String getStringWithoutIDErrorCode = response.replaceAll(Pattern.quote(getIDErrorCodeString), "");
String getStringwithBracket = "}]}]" + getStringWithoutIDErrorCode + "}}[{";
String actualResults = getStringWithoutIDErrorCode.replaceAll(Pattern.quote(getStringwithBracket), ",");
return actualResults;
}
The original string had the }}[{ in the beginning of the line which got removed in the actual results but still pattern is not recognizing and finding the correct string to replace not just in the beginning but in the entire string. Anyone knows how to do this?
}}[{characters from it right ?}]}]}}[{needs to be replaced. At the end we need to keep it. So how do I replace it only in the middle ?