我有这样的网址
https://www.domain.com/course/undergraduate/details/name/subject-name/alpha/a/search-all/
Expected URL : https://www.domain.com/course/undergraduate/subject-name
要获得预期的网址,我确实喜欢这个
$parse=parse_url($url);
$scheme=$parse['scheme'];
$host=$parse['host'];
$path=$parse['path'];
$posted = substr($path, 0, strpos($path, "/alpha/"));
$segments = explode('/', $posted);
$numSegments = count($segments);
unset($segments['3']);
unset($segments['4']);
$new_url=implode("/",$segments);
echo $scheme."://".$host.$new_url;
在这里,我不想遵循这些过程。我需要简化此过程以获得预期的URL。任何人都可以建议如何用正则表达式实现