Use code PERFMATTERS for an additional 10% off!

How to Disable or Enable Scripts with Regex

You can disable or enable scripts in the Perfmatters Script Manager using Regex (regular expressions). This is especially helpful for sites that have a more complex URL structure in place or dynamically generated pages.

How to Use Regex

If you aren’t familiar with Regex, we recommend utilizing this online tool: regex101.com. Kinsta also has some great examples of how to use Regex.

Disable Scripts Using Regex

Let’s say for example you wanted to disable scripts across your category URLs, but nowhere else. In this case, you could use a regular expression for the category URL. With regular expressions, there are multiple ways you can write them, here are a few variations that would work.

Variation 1

This disables the script whenever the URl contains the word category.

(category)
Disable script with Regex
Disable script with Regex

Variation 2

This disables the script whenever the URl contains /category/.

(\/category\/)

Variation 3

This disables the script whenever the URl contains https://domain.com/category/.

(https:\/\/domain.com\/category\/)

Enable Scripts Using Regex

You can also use Regex as an exception when disabling the script everywhere.

Was this article helpful?

Related Articles