import re def set_image_url_resolution_by_mask( image_url: str, change_resolution_to: int, expression_to_find: str = "[1-9][0-9][0-9][0-9]x[0-9][0-9][0-9][0-9]", ) -> str: """Change delphi image_url resolution searched with "expression_to_find" format and replace it by change_resolution_to Args: image_url: str URL change_resolution_to: int value of a preferable resolution expression_to_find: re of a resolution format to search in image_url Returns: Updated with change_resolution_to resolution image url or returned the same image_url if resolution is not found """ search = re.findall(expression_to_find, image_url) result = image_url.replace(search[0], f"{change_resolution_to}x{change_resolution_to}") if search else image_url return result