In PHP regex, what is the significance of making a pattern non-greedy and how does it impact the search and replace process?

When using regex in PHP, making a pattern non-greedy means that the pattern will match the smallest possible substring that satisfies the pattern, rather than the largest possible substring. This can be useful when you want to match specific content within a larger string without capturing more than necessary. Example PHP code snippet:

// Original string
$string = "This is a <b>bold</b> example";

// Using non-greedy pattern to match content within <b> tags
$pattern = '/<b>(.*?)<\/b>/';
$replacement = '[$1]';

// Perform the search and replace
$new_string = preg_replace($pattern, $replacement, $string);

// Output the modified string
echo $new_string;