[英]php preg_match() regular expression
I am working on SEO thing in project to match best URL from possible url's, so i am trying to match request url using preg_match()
function from url pattern 我正在研究项目中的SEO事物,以匹配可能来自url的最佳URL,所以我正尝试使用url模式中的
preg_match()
函数来匹配请求url。
can anyone please help me create regular expression to match only specific urls from all urls, i am newbie in Regular expression, please see my stuff 谁能帮我创建正则表达式以匹配所有URL中的特定URL,我是正则表达式的新手,请参阅我的东西
following 6 urls, 以下6个网址,
1) http://domain.com/pressrelease
1) http://domain.com/pressrelease
2) http://domain.com/pressrelease/2) http://domain.com/pressrelease/
3) http://domain.com/pressrelease/index/13) http://domain.com/pressrelease/index/1
4) http://domain.com/pressrelease/index/1/1/14) http://domain.com/pressrelease/index/1/1/1
5) http://domain.com/pressrelease/inde2x/5) http://domain.com/pressrelease/inde2x/
6) http://domain.com/pressrelease/inde2x/26) http://domain.com/pressrelease/inde2x/2
i want to match 1,2,3
urls, other 3 invalid 我想匹配
1,2,3
网址,其他3个无效
i create this regular expression but it's does not working 我创建了这个正则表达式,但是它不起作用
(\/pressrelease\/)+((?!index).)*$
I don't really see all the point of your request. 我真的看不到您的要求。
(@^http[s]?://[^/] /[^/] ?(/?(index/[^/])?)?$@) (@ ^ http [s]?:// [^ /] / [^ /] ?(/?(index / [^ /])?)?$ @)
This will resolve your 1,2,3 but not the 4,5,6 这将解决您的1,2,3,但不能解决4,5,6
https://regex101.com/r/fQ0hZ8/2 https://regex101.com/r/fQ0hZ8/2
This is 100% working: 这是100%正常工作:
/(\/pressrelease)(\/)?((index))?(\/1)?$/m
https://regex101.com/r/kD9uD9/1 https://regex101.com/r/kD9uD9/1
Here isn't a way to cheat around it 这不是欺骗它的方法
If you wanted to capture the whole string 如果您想捕获整个字符串
(http:\/\/.*pressrelease(()|(\/)|(\/index)|(\/index\/[^\/]*)))$
https://regex101.com/r/aI0fB1/1 https://regex101.com/r/aI0fB1/1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.