简体   繁体   English

如何辨别URL包含一个特定的单词和一个大于1的数字,但这不是开头

[英]How to tell a URL contains a specific word and a number higher than one, but it's not at the beginning

Sorry for the disastrous title, it's hard to concisely phrase what I need. 很抱歉为您带来灾难性的标题,很难简明扼要地表达我的需求。

I'm writing a userscript. 我正在写一个用户脚本。

I want the userscript to only apply to specific parts of a website, but the part I want isn't at the beginning of the URL so I can't do URL starts with: . 我希望用户脚本仅适用于网站的特定部分,但是我想要的部分不在URL的开头,因此我无法执行以以下开头的URL URL starts with:

I know I can use URLs matching the regular expression: instead, but I don't know how to write that so it selects the part I'm after. 我知道我可以使用URLs matching the regular expression:而是,但是我不知道该怎么写,因此它选择了我所需要的部分。

The part of the URL I want to isolate is at the very end. 我想隔离的URL部分在最后。

I've been searching for days. 我一直在寻找几天。 No example I find works for me. 没有找到适合我的例子。

The URL looks like this: 该URL如下所示:

http://www.website.com/some/extra/words/seriously-lots/of/more/stuff/page=3 http://www.website.com/some/extra/words/seriously-lots/of/more/stuff/page=3

I want to isolate any page after 1. The userscript should not activate on page 1. Only pages after it. 我想隔离1 之后的任何页面。不应在第1页上激活用户脚本。 So I'm looking for something that will isolate page=(>1) but I don't know if that exists. 所以我正在寻找可以隔离page=(>1)东西,但我不知道那是否存在。

Based on further details in the comments this is a regex that finds all pages > 1 on the given website as required: 根据评论中的更多详细信息,这是一个正则表达式,可根据需要在给定网站上查找所有> 1的页面:

 .*toyhou\.se\/.+page=[2-9][0-9]* 

It will match [ANYTHING or NOTHING]toyhou.se/[ANYTHING]page=[Number greater than 1] 它将匹配[ANYTHING或NOTHING] toyhou.se/ [ANYTHING] page = [数字大于1]

I use something similar to this. 我使用类似的东西。 You could try: 您可以尝试:

$url = $_SERVER['REQUEST_URI']; 
$explode = explode('=', $url);  
$page =$explode[1]; 

if($page >= 2){ 
//do something

} 

There may be a better way but this should work. 也许有更好的方法,但是应该可以。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM