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 except for Forms, as well as block IP addresses.
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.
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 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.
Below are the most common Regular Expressions used within Hotjar to help you get started. If you're unfamiliar with Regular Expressions, we highly recommend taking a quick crash course!
- 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
Need help building your Regular Expressions?
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)
Wildcard excluding a certain pattern
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: