import java.util.*;
import java.util.regex.*;

class Ideone
{
	public static void main (String[] args) throws java.lang.Exception
	{
		String text = "text text [[ ia asd ]] [[asdasd]] dfgd dfaf sddgsd [[sss aaa]]";
		Pattern p = Pattern.compile("\\[\\[.*?]]");
		Matcher m = p.matcher(text);
		StringBuffer buffer = new StringBuffer();
		while(m.find()) {
		    m.appendReplacement(buffer, m.group().replaceAll("\\s+", ""));
		}
		m.appendTail(buffer);
		System.out.println(buffer.toString());
		
		System.out.println(text.replaceAll("(\\G(?!^)|\\[\\[)((?:(?!]]).)*?)\\s+(?=.*?]])", "$1$2"));
	}
}