diff --git a/include/class.format.php b/include/class.format.php
index b0aafa229b5430146889df00749d5754e3a50747..50c6279fcd2280655c2c30ad118729715563833a 100644
--- a/include/class.format.php
+++ b/include/class.format.php
@@ -228,7 +228,7 @@ class Format {
     function localizeInlineImages($text) {
         // Change file.php urls back to content-id's
         return preg_replace(
-            '/src="(?:\/[^"]+?)?\/file\\.php\\?(?:\w+=[^&]+&(?:amp;)?)*?key=([^&]+)[^"]*/',
+            '`src="(?:https?:/)?(?:/[^/"]+)*?/file\\.php\\?(?:\w+=[^&]+&(?:amp;)?)*?key=([^&]+)[^"]*`',
             'src="cid:$1', $text);
     }