Matcher replaceAll
import java.util.regex.Matcher; import java.util.regex.Pattern; public class MatcherReplaceAllExample { public static void main(String args[]) { Pattern p = Pattern.compile("(i|I)ce"); //create the candidate String String candidateString = "I love ice. Ice is my favorite. Ice Ice Ice."; Matcher matcher = p.matcher(candidateString); String tmp = matcher.replaceAll("Java"); System.out.println(tmp); } }