[英]php preg_match() regular expression
我正在研究项目中的SEO事物,以匹配可能来自url的最佳URL,所以我正尝试使用url模式中的preg_match()
函数来匹配请求url。
谁能帮我创建正则表达式以匹配所有URL中的特定URL,我是正则表达式的新手,请参阅我的东西
以下6个网址,
1) http://domain.com/pressrelease
2) http://domain.com/pressrelease/
3) http://domain.com/pressrelease/index/1
4) http://domain.com/pressrelease/index/1/1/1
5) http://domain.com/pressrelease/inde2x/
6) http://domain.com/pressrelease/inde2x/2
我想匹配1,2,3
网址,其他3个无效
我创建了这个正则表达式,但是它不起作用
(\/pressrelease\/)+((?!index).)*$
我真的看不到您的要求。
(@ ^ http [s]?:// [^ /] / [^ /] ?(/?(index / [^ /])?)?$ @)
这将解决您的1,2,3,但不能解决4,5,6
如果您想捕获整个字符串
(http:\/\/.*pressrelease(()|(\/)|(\/index)|(\/index\/[^\/]*)))$
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.