Why is preg_replace() often considered a faster alternative to ereg_replace()?

preg_replace() is often considered a faster alternative to ereg_replace() because preg_replace() uses Perl-compatible regular expressions which are generally more efficient than the POSIX-style regular expressions used by ereg_replace(). Additionally, preg_replace() is a more modern and actively maintained function in PHP, while ereg_replace() is deprecated as of PHP 5.3.0 and removed in PHP 7.0.0.

// Using preg_replace() instead of ereg_replace()
$pattern = '/\b(\w+)\b/';
$replacement = '<b>$1</b>';
$string = 'This is a sample string.';
$new_string = preg_replace($pattern, $replacement, $string);
echo $new_string;