I am having trouble matching trailing slashes. What I need to do is match any amount of trailing slashes then cut them off if they exist.... so in the code below there could also be ///// slashes at the end I am pretty sure my regex is not correct so any help would be great. <? $lastref = 'http://domain.net/'; $slashes = '/\/$/'; while (preg_match($slashes,$lastref)){ $lastref = rtrim("$lastref", '/'); } echo $lastref; ?> Code (markup): Thanks in advance Edit woops.........I just figured it out!