I have a string and I need to replace || '-' || with , using regex.
Please find the code below:
String str= "str1 || '-' || str2";
str.replaceAll("|| '-' || ", ",");
This replaceAll method is not working. Can anyone please suggest the correct way.
Output should be: str1,str2
Strings are immutable. You are not actually reassigning yourstrvariable with the result of thereplaceAll. Also,replaceAlltakes a regular expression as an input. Usereplace()if you don't actually want to work with regex (this way you wont have to deal with things such as escaping the pipes).|must escaped with backslash. So try\|\|.