- preg_replace: documentation ( source)
<?php
$text = "[url=https://test.com]my link[/url]";
echo preg_replace('~\[url=([^][\s]+)]([^][]*)\[/url]~', "<a href='$1' target='_blank'>$2</a>", $text) . PHP_EOL;
echo preg_replace('~\[url=([^][\s]+)](.*?)\[/url]~s', "<a href='$1' target='_blank'>$2</a>", $text);