What are the potential pitfalls of using greedy quantifiers in regular expressions for URL extraction in PHP?

Using greedy quantifiers in regular expressions for URL extraction in PHP can lead to unintended matches of longer URLs than intended. To solve this issue, you can use the non-greedy quantifier '?' to make the matching process lazy, matching the shortest possible string.

// Using non-greedy quantifier '?' to extract URLs from a string
$string = "Visit our website at https://www.example.com and check out our products at https://www.example.com/products";
$pattern = '/https:\/\/\S+?\.com/';
preg_match_all($pattern, $string, $matches);

// Output the matched URLs
print_r($matches[0]);