import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Example {
public static void main(String[] args) {
final String regex = "\\[\\[Image:[^]]+link=[^]]+]]";
final String string = "$t = [[Image:United Kingdom images gbr image031 jpg.png|141px|link=HomePage|United Kingdom images gbr image031 jpg.png]]\n"
+ "[[Image:United Kingdom images gbr image030 jpg.png|141px|United Kingdom images gbr image030 jpg.png]]\n"
+ "[[Image:United Kingdom images gbr image031 jpg.png|141px|link=Contact|United Kingdom images gbr image031 jpg.png]];\n\n"
+ "<span class=\"United Kingdomtemplate_colour\">Additional remarks</span><br> <br> Green sign with white and yellow text with blue plate with white text displaying that the indicated direction(s) lead to a motorway. [[Image:United Kingdom images gbr image031 jpg.png|141px|link=Home Page|United Kingdom images gbr image031 jpg.png]]<br>White sign with black text with blue plate with white text displaying that the indicated direction(s) lead to a motorway. [[Image:United Kingdom images gbr image046 jpg.png|292px|United Kingdom images gbr image046 jpg.png]]<br> <br> <span style=\"vertical-align: top;\">White sign with black text with blue plate with white text displaying that the indicated direction(s) lead to a motorway. </span> [[Image:United Kingdom images gbr image2550 jpg.png|368px|United Kingdom images gbr image2550 jpg.png|link=Contact]]";
final String subst = "[noinclude]$0[/noinclude]";
final Pattern pattern = Pattern.compile(regex);
final Matcher matcher = pattern.matcher(string);
// The substituted value will be contained in the result variable
final String result = matcher.replaceAll(subst);
System.out.println("Substitution result: " + result);
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html