How to replace case-insensitive literal substrings in Java
If you don't care about case, then you perhaps it doesn't matter if it returns all upcase:
target.toUpperCase().replace("FOO", "");
String target = "FOOBar";
target = target.replaceAll("(?i)foo", "");
System.out.println(target);
Output:
Bar
It's worth mentioning that replaceAll
treats the first argument as a regex pattern, which can cause unexpected results. To solve this, also use Pattern.quote
as suggested in the comments.