How can regular expressions, such as preg_replace(), be utilized in PHP to manipulate and format web addresses for display as clickable links?

Regular expressions can be utilized in PHP, specifically with functions like preg_replace(), to manipulate and format web addresses for display as clickable links. By using a regular expression pattern to match URLs within a string, we can then replace those URLs with HTML anchor tags to create clickable links. This allows for dynamically converting plain text URLs into clickable links for improved user experience.

<?php
$text = "Check out this website: https://example.com";
$pattern = '/(https?:\/\/[^\s]+)/';
$replacement = '<a href="$1" target="_blank">$1</a>';
$formatted_text = preg_replace($pattern, $replacement, $text);
echo $formatted_text;
?>