I would suggest using this more flexible non-greddy regex:
]+?href=\"(http:\/\/[^\"]+?\/([^\"]*?)\.(jpg|jpeg|png|gif))[^>]*?>[^<]*?<\/a>
And a more complex regex (including PHP test code) to hopefully please Gumbo :)
This will be ignored.
Lorem ipsum..
This will be ignored.
This will be ignored.
asdlaskjd>This will be ignored.
This will be ignored.
Something:
This will be ignored.
This will be ignored.
This will be ignored.
Something else...
This will be ignored.
be ignored.
END;
$regex = "/\s]+))?)+?\s+href\s*=\s*(\"(http:\/\/[^\"]+\/(.*?)\.(jpg|jpeg|png|gif))\"|'(http:\/\/[^']+\/(.*?)\.(jpg|jpeg|png|gif))'|(http:\/\/[^'\">\s]+\/([^'\">\s]+)\.(jpg|jpeg|png|gif)))\s(\s*\w+(\s*=\s*(\".*?\"|'.*?'|[^'\">\s]+))?)+>[^<]*?<\/a>/i";
$replaced = preg_replace($regex, '
', $test_data);
echo ''.htmlentities($replaced);
?>