I need to replace a value between two dollar($) symbol.
below is the way i tried but i dont think it is an elegant way to do.
String queryNoAdditionalFilter= SELECT PRODUCTNAME,PRODUCTSKEY FROM PRODUCTS WHERE PRODUCTID=$productid$
int start= queryNoAdditionalFilter.indexOf("$");
int end= queryNoAdditionalFilter.lastIndexOf("$");
String valueSubstitutedToFilter1 = queryNoAdditionalFilter.substring(start+1, end);
String keyToReplace = "\\$"+valueSubstitutedToFilter1+"\\$";
String valueSubstitutedToFilter2=queryNoAdditionalFilter.replaceAll(keyToReplace, "401250");
final outcome is :SELECT PRODUCTNAME,PRODUCTSKEY FROM PRODUCTS WHERE PRODUCTID=401250
which is the best way to implement this logic through java code?
Need your advise.