fork(2) download
  1. import java.util.*;
  2. import java.util.regex.*;
  3.  
  4. class Ideone
  5. {
  6. public static void main (String[] args) throws java.lang.Exception
  7. {
  8. String exp = "foofoobarfoo";
  9. exp = Pattern
  10. .compile("(foo)(foo)")
  11. .matcher(exp)
  12. .replaceAll(gr -> gr.group(1) + "911" + gr.group(2) + "911");
  13.  
  14. System.out.println(exp); // foo911foo911barfoo
  15. }
  16. }
Success #stdin #stdout 0.15s 48736KB
stdin
Standard input is empty
stdout
foo911foo911barfoo