How can the greedy modifier affect the output of regular expressions in PHP?

The greedy modifier in regular expressions in PHP can cause the pattern to match more text than intended by consuming as much of the input as possible. This can lead to unexpected results or incorrect matches. To solve this issue, you can use the non-greedy modifier "?" to make the quantifiers match as little text as possible.

// Using the non-greedy modifier to match as little text as possible
$pattern = '/<.*?>/'; // Non-greedy modifier added with "?"
$text = '<p>This is a paragraph</p>';
preg_match($pattern, $text, $matches);
print_r($matches);