fork(1) 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 text = "text text [[ ia asd ]] [[asdasd]] dfgd dfaf sddgsd [[sss aaa]]";
  9. Pattern p = Pattern.compile("\\[\\[.*?]]");
  10. Matcher m = p.matcher(text);
  11. StringBuffer buffer = new StringBuffer();
  12. while(m.find()) {
  13. m.appendReplacement(buffer, m.group().replaceAll("\\s+", ""));
  14. }
  15. m.appendTail(buffer);
  16. System.out.println(buffer.toString());
  17.  
  18. System.out.println(text.replaceAll("(\\G(?!^)|\\[\\[)((?:(?!]]).)*?)\\s+(?=.*?]])", "$1$2"));
  19. }
  20. }
Success #stdin #stdout 0.09s 50300KB
stdin
Standard input is empty
stdout
text text [[iaasd]] [[asdasd]] dfgd dfaf sddgsd [[sssaaa]]
text text [[iaasd]] [[asdasd]] dfgd dfaf sddgsd [[sssaaa]]