$output = preg_replace("@((?:\w+\.)+(?:jpg|png|webp|jpeg))@gi", '<img src="$1" alt="alt">', $str);
https://regex101.com/r/oJV7Fc/3