A Regular Expression, REGEX, is a special text string for describing a search pattern. Within Hotjar, you can define a Regular Expression to target a specific string or pattern within URLs for all of our tools, as well as block IP addresses in your Hotjar dashboard.
Watch out for common mistakes
- If you include the start and end characters (^ and $) then any URL that includes text before or after the pattern will not be matched. Avoid using them. It's very common for URLs to include query strings at the end, such as the UTM parameter that are added to URLs for tracking purposes. An example would be:
- A forward-slash (/) at the end of the URL is generally optional. If your REGEX includes that character at the end, then a visit to the same URL but without the forward-slash wouldn't match. It is better not to include that final forward slash character.
- There is a limit of 750 characters for all of our REGEX targeting rules. If you go over this limit, there will be no error thrown to alert you of the issue.
Need help building your Regular Expressions?
If you're unfamiliar with Regular Expressions and would like to learn more, we highly recommend taking a quick crash course!
For page targeting, when setting up your tool, there will be a Page Targeting option in which Regular Expressions can be set as the targeting option.
- Wildcard examples (where * can be anything)
- Wildcard excluding a certain pattern
- Excluding certain words or patterns in a URL
- Multiple pages which don't follow any pattern
Is your REGEX not working?
This REGEX tester can help you build regular expressions. Make sure 'JavasScript' is selected in the menu on the left.
Wildcard examples (where * can be anything)
All pages which match the pattern but do not include the word "article" or "post" www.example.com/pages/*/subpage
Excluding certain words or patterns in a URL
All pages which do not include "/somepage" and "/someotherpage"
Pages which include the word "page" and do not include "somepage":
Multiple pages which don't follow any pattern
Target these three pages:
Blocking IPs with Regular Expressions
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".
Block the IPs 192.168.0.14 - 192.168.0.62
Block the IPs 192.168.0.0 - 192.168.0.255
IP Range Regular Expression Builder
To generate IP ranges in regex format, check out this free tool:
Block all these IPs: