In this article, we will see how to use regex to replace all word occurrences in Java. We will use "." as pattern. "." indicates any char acter but 1 char acter as single.
Lets look to our code.
String s1;
s1.replaceAll("rom.","---");
Lets see it in an example.
In above example, we replaced all "rom" occurrence within string . Following "rom", 1 extra single char acter is replaced due to regex pattern "." match it. Notice that "e" is replaced and result was "and---da". We print it to terminal.