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

326 Views Asked by At

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:.

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.

The part of the URL I want to isolate is at the very end.

I've been searching for days. No example I find works for me.

The URL looks like this:

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. So I'm looking for something that will isolate page=(>1) but I don't know if that exists.

2

There are 2 best solutions below

0
Pinkie Pie On BEST ANSWER

Based on further details in the comments this is a regex that finds all pages > 1 on the given website as required:

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

It will match [ANYTHING or NOTHING]toyhou.se/[ANYTHING]page=[Number greater than 1]

1
John On

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.