我正在尝试写wordpress相当永久链接正则表达式。
我有以下网址。我需要2场比赛,
1st:/ /之前的最后一个词/ 2nd:以get /开头的字符串 Url可能就像这些
http://localhost/akasia/yacht-technical-services/yacht-crew/get/gulets/for/sale/
在这里,我需要“游艇船员”和“get / gulets / for / sale /”
http://localhost/akasia/testimonials/get/motoryachts/for/sale/
这里我需要“推荐”并获得/ motoryachts / for / sale /
http://localhost/akasia/may/be/lots/of/seperator/but/ineed/last/get/ships/for/rent/
这里我需要“最后”并获得/ ship / for / rent /
$url1 = 'somepage/get/gulets/for/sale'; // I need somepage and get/gulets/for/sale
$url2 = 'somepage/subpage/get/motoryachts/for/rent'; // I need subpage and get/motoryachts/for/rent
$url3 = 'may/be/unlimited/directories/but/i/need/here/get/ships/for/sale'; // I need here and get/ships/for/sale
$url4 = 'services/get/gulets/for/sale'; // I need services and get/gulets/for/sale
$regex = '([^\/]+?)\/(get\/.+)';
// I can not change anything below.
preg_match("#^$regex#", $url4, $matches);
echo "<pre>";
print_r($matches);
echo "</pre>"
我抓住了$ url4但是没有$ url1,$ url2,$ url3
如果有人帮忙,我感激不尽。