How can the /U modifier in regular expressions help prevent unintended removal of content in PHP?

The /U modifier in regular expressions can help prevent unintended removal of content in PHP by making the quantifiers in the regular expression lazy instead of greedy. This means that the regular expression engine will try to match as few characters as possible, which can prevent it from unintentionally removing content that should be preserved.

$string = "This is a test string";
$pattern = '/\b\w+\b/U'; // Using the /U modifier to make the quantifier lazy
preg_match_all($pattern, $string, $matches);
print_r($matches[0]);