import re
regex = re.compile(r"\[\[Image:[^]]+link=[^]]+]]")
test_str = ("$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]]")
subst = "[noinclude]$0[/noinclude]"
result = regex.sub(subst, test_str)
if result:
print(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 Python, please visit: https://docs.python.org/3/library/re.html