Topics & Examples:
A Regular Expression (regex or regexp for short) is a special text string for describing a search pattern. You can think of regular expressions as wildcards on steroids.
It is unlimited what a regular expression can include and/or exclude. Here we will be listing the most popular user-requested examples:
Wildcard examples: (where * can be anything)
3: www.example.com/user/<user_id>/profile/ (numeric user_id)
Wildcard excluding a certain pattern:
Target all pages which match the pattern but do not include the word "article" or "post":
Excluding certain words or patterns in a URL:
1: Target all pages which do not include "/somepage" and "/someotherpage"
2: Target pages which include the word "page" and do not include "somepage"
Multiple pages which don't follow any pattern:
Target these three pages:
It is best to avoid defining the domain (www.example.com) when writing Regular Expressions in Hotjar URL fields.
Depending on how your server is set up, the different pages on your site can be referenced in either one of these cases or both:
The difference is the trailing / at the end. In most cases, this is usually the same page showing the same content, however since this is not necessarily the case, Hotjar doesn't assume it is since it could potentially skew results such as Heatmaps.
This is usually a problem when you set up a Heatmap using the following URL:
But you site or external sites are linking to this version of the URL:
How to target both URLs using a Regular Expression
In order to target both the examples shown above, this simple Regular Expression can help you do that:
This regular expression will match visits if the URL ends with '/products' OR '/products/'.
If the URL you intend to target might contain a query string or fragment you'll need to use a slightly more complex expression:
This regular expression will match visits if the URL ends with '/products' OR '/products/', as well as '/products?name=value' and '/products/#fragment'.
If you are setting up a Heatmap, you will notice Hotjar asks you for a 'Screenshot Page URL'. Simply set the screenshot page to one of the variations, such as "www.example.com/products"
IP Range Regular Expression Builder
We highly recommend using this tool to generate IP ranges in regex format:
The examples below are just examples using local IPs. When using IP Blocking you should use public IPs.
Simple IP match (single IP):
192.168.0.1 or 192\.168\.0\.1
Both would work since in regex, the "." character means "any character".
192.168.0.14 - 192.168.0.62
192.168.0.0 - 192.168.0.255
CIDR notation IPs:
For CIDR notation IPs, you can use this CIDR to regex converter: http://d.xenowire.net/cidr2regex.php
Target all these IPs: