这里的URI路径我需要解析:正则表达式为URI路径的第一3个部件
大鼓/ SAM /β-类森林%E2%84%A2 /产物的一个
我需要只提取前三个以斜线结尾的组件。
preg_match("/^([\w\/ %\.-]*){3}/", $input_line, $output_array);
这几乎得到我想要的,但它不包括'%E2%84%A2'。我一直在重新排列http://www.phpliveregex.com/的东西,但无济于事。
请注意,如果我尝试解析完整的URL,说mysite.com/tom-tom/sam/beta-forest%E2%84%A2/product-a,那么这个正则表达式得到我想要的:
的preg_match(“/^(https?://)?([\da-z.-]+).([az.]{2,6})([/\w %。 - ] *){3} //“,$ path,$ output_array);
我需要解析URI路径,但我需要包含%符号。叹气..
编辑:
我的预期成果是:
tom-tom/sam/beta-forest%E2%84%A2/
什么是你期望的输出? – 2014-09-23 15:08:15
也许parse_url可能对你有用http://mx1.php.net/manual/es/function.parse-url.php – 2014-09-23 15:08:32
@Alx http://regex101.com/r/rD4sO4/2 – 2014-09-23 15:10:08