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 Link to comment https://forums.phpfreaks.com/topic/150902-solved-just-cant-see-why/ 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 Link to comment https://forums.phpfreaks.com/topic/150902-solved-just-cant-see-why/#findComment-792734 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. Link to comment https://forums.phpfreaks.com/topic/150902-solved-just-cant-see-why/#findComment-792761 Share on other sites More sharing options...
Adam Posted March 24, 2009 Author Share Posted March 24, 2009 Perfect, thanks a lot! Adam Link to comment https://forums.phpfreaks.com/topic/150902-solved-just-cant-see-why/#findComment-792805 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.