Java String replaceAll with conditions
- by user1483570
I am not good in regular expressions and I need help in replacing the string.
String str = "Name_XYZ_";
str = "XYZ_NAME_";
So how can I replace "Name_" or "_NAME_" from above two strings with empty string?
The conditions are "Name" can be in any case and it can be at index 0 or at any index but preceded by "_".
So far I tried,
String replacedString = str.replaceAll("(?i)Name_", ""); // This is not correct.
This is not the homework. I am working on XML file that needs such kind of processing.
Please help.
Thank you.