Match specific urls but not including a php file - regex

I have the following sample urls
/alfa/wp-includes/js/jquery/jquery.js
/beta/wp-content/plugins/app/js/media.js?parameter=value
/beta/wp-admin/network
/beta/wp-content/themes/journal/data.php
I'm using the following regex to match all paths, excluding paramethers
^/(alfa|beta)((/wp-(content|admin|includes))([^?\s]*)).*
This works well, but how to change the regex to exclude any paths which include a .php ? So it needs to return first 3 paths but not the last.

You can use the PCRE verbs skip and fail to skip over matches of expressions. You can read more about them here, http://www.rexegg.com/backtracking-control-verbs.html#skipfail. For your current example you can use:
.*\.php$(*SKIP)(*FAIL)|^/(alfa|beta)((/wp-(content|admin|includes))([^?\s]*)).*
which would skip files that end in .php.
Demo: https://regex101.com/r/YH3n0x/1/
The .*\.php$ looks for anything until a .php at the end of the string/line.

The solution i looked for is the following, thanks #chris85
.*\.php(*SKIP)(*FAIL)|^/(alfa|beta)((/wp-(content|admin|includes))([^?\s]*)).*

Related

Why is my Regex include filter not working (google analytics)?

In google analytics, I have created the following include filter:
^https:\/\/(my\..*|accounts\..*|maya\..*\/reports\/(mymessages|favorites)|maya\..*\/account\/notification|info\..*\/(heb|eng)\/management\/generalpages\/pages\/(personalfolder|registration|change_password|userssearchindex|security%20search)\.aspx).*
In order to include only URLs that contains the following addresses:
https://my.tase.co.il
https://accounts.tase.co.il
https://maya.tase.co.il/reports/mymessages
https://maya.tase.co.il/reports/favorites
https://maya.tase.co.il/account/notification
https://info.tase.co.ilManagement/GeneralPages/Pages/PersonalFolder.aspx
https://info.tase.co.ilManagement/GeneralPages/Pages/Registration.aspx
https://info.tase.co.ilManagement/GeneralPages/Pages/Change_Password.aspx
https://info.tase.co.ilManagement/GeneralPages/Pages/UsersSearchIndex.aspx
https://info.tase.co.ilManagement/GeneralPages/Pages/Security%20Search.aspx
But for some reason i cant get it to work.
What am I doing wrong?
Thanks for your help!
The pattern does not match the links that start with info. because the pattern specifies info\..*\/(heb|eng) and in the example data there is no heb or eng present.
You can either remove that part or use a pattern that exactlty matches starting with those urls:
https:\/\/(?:(?:accounts|my)\.tase\.co\.il|maya\.tase\.co\.il\/(?:reports\/(?:mymessages|favorites)|account\/notification)|info\.tase\.co\.il\/Management\/GeneralPages\/Pages\/(?:PersonalFolder|Registration|Change_Password|UsersSearchIndex|Security%20Search)\.aspx).*
See a Regex demo.

Regex Adding a URL path except the current one I'm at

I'm trying to add something along the lines of this regex logic.
For Input:
reading/
reading/123
reading/456
reading/789
I want the regex to match only
reading/123
reading/456
reading/789
Excluding reading/.
I've tried reading\/* but that doesn't work because it includes reading/
You must escape your backslashes in Hugo, \\/\\d+.

How do I exclude a folder from a URL using Regex?

I need to use Regex to check for URLs that contain 'folder', in the following URL:
subdomain.domain.co.uk/section/folder/page
I'm using:
subdomain.domain.co.uk\/.*\/(?!folder\/).*
but it's still finding 'folder'. Any ideas?
Try this regex:
^subdomain.domain.co.uk\/((?!folder).)*$
Demo here:
Regex101
First off, you need slashes around "folder", otherwise you'll also exclude "/anotherfolder/" and "/folder.jpg" etc.
Put the negative look ahead before the "." and add "." before "folder":
subdomain.domain.co.uk\/(?!.*\/folder\/).*
This won't match a URL with "/folder/" anywhere in it.

Regex Matching the submatch not having some words

I want to write RewriteRule some part of URL should not end with specific set of words.
URL's like:
/en/drivers/drivername/play
But I want (drivername) section not "ending with specific words, such as "excluded" or "banned"
In other words I want following URL's to work:
/en/drivers/drivername/play
But following not to work:
/en/drivers/drivername-excluded/play
/en/drivers/drivername-banned/play
But this should be working:
/en/drivers/driver-excluded-name/play
/en/drivers/driver-banned-test/play
Is it even possible?
Without exclusion part I was using:
^(en|de)/([^\/]+)/(play|test)?
Try something like this, using a negative lookahead:
(en|de)\/([^\/]+)\/driver.+-(?!(excluded|banned)\/).*?\/(play|test)?
I took your regular expression and inserted the bit dealing with "drivername"
driver.+-(?!(excluded|banned)\/).*?
In this case, (?!(excluded|banned)\/) ensures that the "driver" section between forward slashes does not end with "excluded" or "banned" directly before the following forward slash.
https://regex101.com/r/pC8sP3/3
This appears to be working with your provided examples.

How to add / to the end of a URL using IIS7 Rewrite rules

I need to add a trailing / to a url if it doesn't have one or isn't a file. So
http://www.ddd.com/dasdas
would become
http://www.ddd.com/dasdas/
But I don't what to just add slash the URl as this will end up with filename like this style.css/
So I need a piece of Regex that I can put into the IIS 7 rewrite engeine to append when needed
I am not really familiar with ISS, but if it supports standard regular expressions then I would suggest something like this:
Search pattern: ^.*?\/[\w\d-_]+$
Replace pattern: $0\/