tags:

views:

32

answers:

1

Hi,

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);

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

A: 

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

Colin Fine
That would only match urls that end the string. `$text` could contain many URLs that need to be replaced...
thetaiko
Oh right, I didn't appreciate that. So you want it followed by a non-word char that isn't '/'? Would putting \b in before the (?!/) do it?
Colin Fine
Thx! Colin Fine's 2nd answer works perfectly :)
Xolf
So would you like to accept the answer?
Colin Fine