import java.util.regex.Pattern; class Demo { static Pattern patHello = Pattern.compile("HELLo", Pattern.CASE_INSENSITIVE); public static final void main(String []args) { String in = "before heLLO after"; String out = patHello.matcher(in).replaceAll("Bye"); System.out.println("out=" + out); } }Output:
out=before Bye after