title: Java replace capturing group with different value
body: <p>In java I want to replace only the capturing group in the matched part with some other value and the value to be replaced depends on the capturing group. </p>
  
  <p>Eg:</p>
  
  <pre><code>String str = "fname:hello hello:world ffff:off";
  Map&lt;String, String&gt; mapping = new HashMap&lt;String, String&gt;();
  dat.put("fname", "meme");
  dat.put("hello", "below");
  dat.put("ffff", "ssss");
  Pattern pat = Pattern.compile("([a-zA-Z_]+):");
  </code></pre>
  
  <p>In the above code I want to replace the capturing group part of the pattern "pat" with the corresponding mapping found in the "mapping".
  i.e. After the replacement the "str" string should be transformed to "meme:hello below:world ssss:off"
  How can I achieve this?
  Thanks for the help.</p>