Adam Posted March 24, 2009 Share Posted March 24, 2009 Hey guys, got a regex problem! I'm trying to return: (...)/content/what_ever/may_be/here from a URL. At the moment I'm using: preg_match('/\/content\/[.]+$/', $url, $matches); .. but having little success! Can anyone see where I'm going wrong? At the moment just returns an empty array ??? Thanks for your help, Adam Quote Link to comment Share on other sites More sharing options...
Adam Posted March 24, 2009 Author Share Posted March 24, 2009 Ah got it partly working now using: /\/content\/.+$/ ... but this returns "/content/" as well. "/content/" must be in the string, but I don't want to return it. I could strip out "/content/" afterward, but I'd prefer to just do this in the regular expression, if that's possible? Thanks, Adam Quote Link to comment Share on other sites More sharing options...
nrg_alpha Posted March 24, 2009 Share Posted March 24, 2009 If you don't want to include the /content/, you can do a capture of everything else, and simply use that. preg_match(#/content/(.+)$#, $string, $match) What ever comes after the /content/ will be stored into $match[1], which saves you from needing to strip /content/ out afterwards. EDIT - Of course, change $string to the name of the variable in question that you are using. Quote Link to comment Share on other sites More sharing options...
Adam Posted March 24, 2009 Author Share Posted March 24, 2009 Perfect, thanks a lot! Adam Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.