How can the Ungreedy Modifier be used effectively in PHP regular expressions for extracting content?

When extracting content using regular expressions in PHP, the Ungreedy Modifier (?U) can be used to make the matching behavior non-greedy, meaning it will match as little as possible. This is useful when you want to extract content between two specific patterns without capturing more content than necessary. Example:

$string = "This is a <b>sample</b> text with <i>HTML</i> tags.";
preg_match('/<b>(.*?)<\/b>/', $string, $matches);
echo $matches[1]; // Output: sample

preg_match('/<i>(.*?)<\/i>/', $string, $matches);
echo $matches[1]; // Output: HTML