Skip to content

Watered Down Regex Syntax

gdarko edited this page Sep 6, 2020 · 3 revisions

True Regular Expressions (i.e., the full syntax) can be very handy for a variety of reasons. However, it is also quite complex. More complex than what most Rapid Cache users need. So for that reason, Rapid Cache supports a custom, watered-down version of regex. It can be used in exclusion patterns, custom URLs, and more. This provides a good balance between flexibility and simplicity.

Where is Watered-Down Regex Supported?

Within Rapid Cache, there are many areas that support watered-down regex syntax:

  • URI Exclusion Patterns (supports the full syntax)
  • HTTP Referrer Exclusion Patterns (supports the full syntax)
  • User-Agent Exclusion Patterns (supports the full syntax)
  • Auto-Clear XML Sitemap Patterns (^ and $ are not accepted)
  • Auto-Clear Custom URL Patterns (^ and $ are not accepted)
  • Clearing a Specific URL Pattern (^ and $ are not accepted)

Watered-Down Regex Syntax

The syntax is parsed as plain text (i.e., what you type is what you get), but the following characters are special. These characters were taken from the original/official Regex syntax, and then modified slightly to behave in the following ways that are useful in Rapid Cache:

  • * = 0 or more characters that are NOT a slash /
  • ** = 0 or more characters of any kind, including / slashes.
  • ^ = beginning of the string (not supported in all cases, see list above).
  • $ = end of the string (not supported in all cases, see list above).

Watered-Down Regex Examples

Custom URL Examples

See: Dashboard → Rapid Cache → Plugin Options → Automatic Cache Clearing → Misc. Auto-Clear Options → Custom URLs.

To clear all cache files for URIs under /blog/ (i.e., all Posts):

 /blog/**

In this example, adding the syntax ** will exclude all custom URIs that start with /blog/ and anything infinitely deep beneath that slug.


URI Exclusion Examples

See: Dashboard → Rapid Cache → Plugin Options → URI Exclusion Patterns

If you want to exclude your home page URI, and only the home page URI:

^/$

To exclude a URI that begins with /members/, and only that specific URI:

^/members/$

Tip: There is a difference between * and **. To exclude URIs that start with /members/ and match anything beneath that slug, infinitely deep, you would use ** (double asterisk), which matches 0 or more characters of any kind, including / slashes.

^/members/**

Excludes: /members/, /members/jason/, /members/jason/profile/, /members/groups/a/, /members/groups/b/c/a/edit, etc.


To exclude /members/ and anything beneath that slug, one level deep:

^/members/$
^/members/*/$

Excludes: /members/, /members/jason/, /members/groups/; but NOT /members/groups/a/


To exclude any URI that simply contains /members/ in it anywhere:

/members/

To exclude any URI that simply contains /member/or /members/ or /member[something]/ in it anywhere:

/member*/

Excludes: /member/, /members/, /member-groups/, /member-info/, and /member/groups/ too, because there is no ^ or $ specified; i.e., the match can occur anywhere in the URI, not necessarily from beginning to end.


Auto-Clear XML Sitemap Pattern Examples

See: Dashboard → Rapid Cache → Plugin Options → Automatic Cache Clearing → Sitemap-Related Options → XML Sitemap Patterns.

Searches are performed against the REQUEST_URI; e.g., a request for /sitemap.xml and/or /sitemap-xyz.xml are both matched by the pattern: /sitemap**.xml. Full URLs should not be used; only the URI (everything that comes after the domain). One pattern per line.

If you want to auto-clear /sitemap.xml, /sitemap-1.xml, and /sitemap-2.xml, you could use a pattern like this:

/sitemap*.xml

If you want to auto-clear /sitemap.xml, /sitemap/pages/1.xml, and /sitemap/posts/1.xml, you could use a pattern like this: /sitemap**.xml.

/sitemap**.xml

A note regarding WP Multisite: Any domains mapped to the current site are cleared automatically. In other words, if you enter /sitemap**.xml (the default value for that field) then whenever the cache is cleared for Child Site A, the following are cleared automatically:

  • http://child-a.example.com/sitemap.xml
  • or: http://example.com[/base]/child-a/sitemap.xml
  • and/or: http://[MAPPED DOMAIN]/sitemap.xml (for each domain mapped to child site A)

A note regarding ^ and $: For XML Sitemap Patterns, ^ and $ are always on. Patterns must always match from beginning to end, and for that reason, ^ and $ are always applied (internally). You should avoid using ^ and $ when configuring XML Sitemap Patterns.


Clear Cache Options: Entering a Specific URL Pattern

This pattern will match all of these URLs and clear any cache files associated with those URLs:

https://www.domain.com/my-account
https://domain.com/my-account
http://www.domain.com/my-account

If you also wanted to match anything that might come after my-account (e.g., my-account/, my-account/upgrade/, etc.), you could simply add another ** so that the pattern becomes:

**domain.com/my-account**

To clear the cache for any specific URI that contains /membership/ or /memberships/ or /membership[SOMETHING]/ in it

http://www.domain.com/membership*/

To clear the cache for /membership/ and any pages or posts beneath it, one level deep, add * at the end of the URL:

http://www.domain.com/membership/*

This will clear cache for the following URLs:

http://www.domain.com/membership/pageA/
http://www.domain.com/membership/postB/
http://www.domain.com/membership/group/

A note regarding ^ and $: When clearing a Specific URL, ^ and $ are always on. Patterns must always match from beginning to end, and for that reason, ^ and $ are always applied (internally). You should avoid using ^ and $ when clearing a Specific URL.

Clone this wiki locally