diff --git a/updatecontent.py b/updatecontent.py
index 75f65de95bc2c67489327ec4a4349d2f19cdb588..7024eb77e3470bf519c669685db67e530c48e2c1 100644
--- a/updatecontent.py
+++ b/updatecontent.py
@@ -3,10 +3,10 @@ import os
 import logging
 import shutil
 import re
-from urllib.parse import urlencode
+from urllib.parse import quote
 
 # MD_IMAGE_REGEX = r'!\[(?<altText>.*)\]\s*\((?<imageURL>.+)\)|img\s*src="(?<imageURL1>[^"]*)"\s*alt="(?<altText1>[^"]*)" \/>|img\s*alt="(?<altText2>[^"]*)"\s*src="(?<imageURL2>[^"]*)" \/>'
-OBSIDIAN_IMAGE_REGEX = r'!\[\[(.+\.(png|jpe?g|avif|bmp|gif|svg|webp))(?:\|[0-9]+(?:x[0-9]+)?)?\]\]'
+OBSIDIAN_IMAGE_REGEX = r'!\[\[((.+\.(png|jpe?g|avif|bmp|gif|svg|webp))(?:\|[0-9]+(?:x[0-9]+)?)?)\]\]'
 
 # Initialise logging
 logging.basicConfig(level=logging.INFO)
@@ -56,8 +56,12 @@ for filename in os.listdir(posts_target_dir):
     images = re.findall(OBSIDIAN_IMAGE_REGEX, content)
 
     for image in images:
+        # image[0] is the full match (e.g. filename.png|100x100)
+        # image[1] is the image name (e.g. filename.png)
+        # image[2] is the image extension (e.g. png)
+        
         # Get the image name
-        image_name = image[0]
+        image_name = image[1]
         image_path = os.path.join(images_source_dir, image_name)
 
         logger.debug(f"Processing image {image_name}")
@@ -73,9 +77,9 @@ for filename in os.listdir(posts_target_dir):
         shutil.copy(image_path, target_image_path)
 
         # Replace the image path in the content
-        image_url_name = urlencode(image_name)
+        image_url_name = quote(image_name)
         md_link = f"![{image_name}](/images/{image_url_name})"
-        content = content.replace(f"![[{image_name}]]", md_link)
+        content = content.replace(f"![[{image[0]}]]", md_link)
 
     # Write the updated content back to the file
     with open(filepath, "w") as file: