[英]pcre(php) regular expression to match url
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 3 urls 以下3个网址
1). 1)。 http://domain.com/pressrelease/index/1 http://domain.com/pressrelease/index/1
2). 2)。 http://domain.com/pressrelease/123 http://domain.com/pressrelease/123
3). 3)。 http://domain.com/pressrelease/blah http://domain.com/pressrelease/blah
i want to match 2,3
urls, urls have not contain of index/(:num)
after pressrelease
我想匹配2,3
网址, pressrelease
后网址中不包含index/(:num)
i create this regular expression but it's does not working 我创建了这个正则表达式,但是它不起作用
(\/pressrelease\/)+((?!index).)*$
Since you're passing the regex to preg_match
, the below regex would be fine. 由于您要将正则表达式传递给preg_match
,因此下面的正则表达式就可以了。
\/pressrelease\/(?!index\/\d+\b).*
(?!index\\/\\d+\\b)
negative lookahead assertion which asserts that the match /pressrelease/
won't be followed by the string which is in the format like index/number
. (?!index\\/\\d+\\b)
否定超前断言,断言匹配/pressrelease/
后面不会是index/number
这样的格式的字符串。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.