Use StringUtils apache commons lang3 - v3.5 or later (so you don't need to worry about regex):
StringUtils.replaceIgnoreCase(text, searchString, replacement);
or
StringUtils.replaceOnceIgnoreCase(text, searchString, replacement);
If you are using maven, add this dependency (I am using version 3.6):
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.6</version>
</dependency>
source
share