Java tutorial
public class Main { public static void main(String[] args) { // \\b to get \b inside the string literal. String regex = "\\bJava\\b"; String replacementStr = "XML"; String inputStr = "Java and Javascript"; String newStr = inputStr.replaceAll(regex, replacementStr); System.out.println("Regular Expression: " + regex); System.out.println("Input String: " + inputStr); System.out.println("Replacement String: " + replacementStr); System.out.println("New String: " + newStr); } }