DavidJB
DavidJB

Reputation: 2362

PCRE Pattern match to URL

I'm trying to configure a website plugin and need to set a PCRE url pattern for certain pages on my site.

I exclude certain pages using the following patterns successfully.

^/wp-admin/
^/wp-login.php
^/content/

However I also need to exclude pages which are in the following patterns

www.site.com/post_id/post_name/feed/
e.g. www.site.com/345345/myawesomepost/feed/

Where the only static component of the url is /feed/ Would anyone know how to do this using PCRE expressions..?

Upvotes: 1

Views: 3405

Answers (3)

aliteralmind
aliteralmind

Reputation: 20163

To exclude urls like this

Format:  www.site.com/post_id/post_name/feed/
Example: www.site.com/345345/myawesomepost/feed/

you might consider the following regular expression:

^(?:\w+\.)+\w+/[0-9]+/\w+/feed/$

Regular expression visualization

Debuggex Demo

Free-spaced:

Here is an more general and comprehensive answer on using regex to match urls, that may also be of interest.


(All the above links come from the Stack Overflow Regular Expressions FAQ, under "Common Tasks > Validation > Internet". Please consider bookmarking the FAQ for future reference.)

Upvotes: 1

Johan Vranckx
Johan Vranckx

Reputation: 270

This is what I would use:

/www.+\/feed\//gi

will match:

www.site.com/post_id/post_name/feed/
www.site.com/345345/myawesomepost/feed/

If the urls contain 'http://', you should alter the pattern to:

/http.+\/feed\//gi

The 'i' at the end can be left out if you are sure 'feed' will never contain capital letters.

Upvotes: 0

Woodham
Woodham

Reputation: 4273

Domething like this should match

^/.+/feed/

It just matches every url that ends with /feed/

Upvotes: 0

Related Questions