1

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

DavidJB
  • 2,272
  • 12
  • 30
  • 37

3 Answers3

1

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

Community
  • 1
  • 1
aliteralmind
  • 19,847
  • 17
  • 77
  • 108
0

Domething like this should match

^/.+/feed/

It just matches every url that ends with /feed/

Woodham
  • 4,053
  • 2
  • 20
  • 15
0

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.

Johan Vranckx
  • 250
  • 3
  • 7