I need a regular expression that matches two virtual folders; the first and the last in a given URL:
www.example.com/first_folder/some/additional/bunch/of/folders/last_folder/
so far I have this regex: (?<!/)/[^/?#]+
but it matches all the folders 🙁
I need this for a rewrite rule to use in WordPress. A Quick and dirty example for rewriting http://mysite/project/1 into http://mysite/index.php?pagename=project&id=1:
$newrules = array();
$newrules['(project)/(d*)$'] = 'index.php?pagename=$matches[1]&id=$matches[2]';
Quick and dirty solution i.e. not thoroughly tested with the billion possible combinations of urls etc. so take it with a grain of salt..
Input :
Output :