开发者

Regex - negative look-ahead assertion

I wand to replace URLs like www.example.com/profile/USERNAME by [user]USERNAME[/user] BBCode!

$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);
开发者_StackOverflow社区

But it also transforms URLs like www.example.com/profile/USERNAME/more/and/more into [user]USERNAME[/user]/more/and/more ... :( It should only transform exactly "/profile/USERNAME".

can somebody help me? thx


Replace (?!/) by $ at the end?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜