If I had this string "dog dog dog" I want to turn it into something like "cat bird turtle".
If I run code like this:
Pattern p = Pattern.compile("dog");
 Matcher m = p.matcher("dog dog dog");
    while(m.find())
       {
          System.out.println("group:"+m.group());
   }
I get something like this:
dog
dog
dog
But is there a way to essentially overwrite each dog once it's found with a different word to get my desired output mentioned above? i.e. dog1 -> cat, dog2 -> bird, dog3 -> turtle
 
     
    