Invalid patterns of exclusions
Certain patterns of exclusions cannot be handled and are automatically removed.
If you add invalid patterns, you will see the following admin notice:
WP Rocket: The following pattern is invalid and has been removed.
This is because the exclusion fields are looking for a Regular Expression (regex) pattern. When that includes characters that have a special meaning, it can cause problems with the regex and will generate a warning in the website's error log.
The following are the special characters that may invalidate a pattern:
- backslash:
\
- caret:
^
- dollar sign:
$
- period or dot:
.
- vertical bar or pipe symbol:
|
- question mark:
?
- asterisk or star:
*
- plus sign:
+
- opening parenthesis:
(
- closing parenthesis:
)
- opening square bracket:
[
- opening curly brace:
{
If you need the Regular Expression to match literally any of the listed special characters, you should escape them by prepending them with a backslash \
.
Examples
The following are examples of exclusions with special characters correctly validated:
unmatched\)closing\)parenthesis
my\(exclusions\]pattern
In a specific example, to match a script like the following:
<script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('set', 'developer_id.dOGY3NW', true); gtag('config', 'UA-40478734-1', { 'allow_google_signals': false, 'link_attribution': false, 'anonymize_ip': true, } );
If you choose to exclude this script from Delay JavaScript Execution and use gtag(
to do, you'll need to escape the parenthesis for the regular expression to match the script: gtag\(
.
But if you want to exclude all files in the /wp-content/
directory you'll need to use (.*)
without escaping, i.e. adding a backslash, the parenthesis:
/wp-content/(.*)