What potential issues can arise when using regex to extract URLs from embed code in PHP?

One potential issue when using regex to extract URLs from embed code in PHP is that the regex pattern may not accurately capture all possible URL formats, leading to some URLs being missed. To solve this, it's important to use a comprehensive regex pattern that covers various URL structures commonly found in embed code.

// Sample code to extract URLs from embed code using a more comprehensive regex pattern
$embed_code = '<iframe src="https://www.example.com/embed"></iframe>';
preg_match_all('/https?:\/\/[\w\-\.]+\.\w{2,5}(?:\/[\w\-\.]*)*\/?/', $embed_code, $matches);

$urls = $matches[0];
foreach ($urls as $url) {
    echo $url . "\n";
}