我想用[user] USERNAME [/ user] BBCode替换www.example.com/profile/USERNAME等网址!
$userURLSearch = "#((https?|ftp)://|www\.)example\.com/profile/([A-Za-z][A-Za-z0-9_-]+)(?!/)#i";
$userURLReplace = "[user]\\3[/user]";
$text = preg_replace($userURLSearch, $userURLReplace, $text);
但它也会将www.example.com/profile/USERNAME/more/and/more等网址转换为[user] USERNAME [/ user] / more /和/ more ...... :( 它应该只改变“/ profile / USERNAME”。
有人能帮帮我吗? THX答案 0 :(得分:1)
最后用$替换(?!/)?