Reputation: 2362
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
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/$
Free-spaced:
^
: Start-of-line anchor(?:
: [Non-capturing group] of \w+\.
: One-or-more word-characters, followed by a literal dot (which could also be written as [.]
)+
: One-or-more times\w+/
: One-or-more word characters followed by a (literal) slash[0-9]+/
: One-or-more digits, followed by a slash\w+/
feed/
: The word "feed" followed by a slash.$
: End-of-line anchorHere 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
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
Reputation: 4273
Domething like this should match
^/.+/feed/
It just matches every url that ends with /feed/
Upvotes: 0