[英]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.