$text = 'Link to [Google](https://www.google.com/)'; echo preg_replace('/[(.*?)]s*(((?:http://|https://)(?:.+)))/', '<a href="$2">$1</a>', $text); // Outputs: Link to <a href="https://www.google.com/">Google</a>