fork download
  1. import java.util.*;
  2. import java.io.*;
  3. import java.util.regex.*;
  4. import java.util.List;
  5.  
  6. class Program {
  7. public static void main (String[] args) throws java.lang.Exception {
  8.  
  9. String subject = "[rotura de lunas]Gar_1 blah [rotura de lunas]noGar";
  10. String replaced = subject.replaceAll("(?s)((\\[[^\\]]*\\])Gar_1)(.*?)(\\2noGar)", "$2noGar$3$4");
  11. System.out.println(replaced);
  12.  
  13. } // end main
  14. } // end Program
Success #stdin #stdout 0.07s 380224KB
stdin
Standard input is empty
stdout
[rotura de lunas]noGar blah [rotura de lunas]noGar