Articles on: Engage - Features
This article is also available in:

How to use RegEx to target specific URLs

With Engage, you can use the “on some pages” display/hide condition to control where your elements appear based on URLs.


This condition works using the “contains” operator.



In most cases, using a standard URL will be sufficient. However, depending on your URL structure and site architecture, entering a simple URL may unintentionally target pages you don’t want.


For example, let’s say you only want to target your homepage:https://www.example.com

If you enter this URL in the display condition:




You will indeed target the homepage—but also any page whose URL contains example.com, which is not the intended behavior.

That’s where RegEx (and its wonderful world) comes in!



What does RegEx mean?


RegEx (short for Regular Expression) is a set of rules that defines which sequences of characters should match in a search.

In other words, it’s a way to describe a pattern in text so it can be automatically identified.

For page targeting, this means matching only the URLs that follow a specific pattern.



Basic RegEx characters

To build a RegEx, you use special characters to define what you’re looking for. Here are some basics:

  • a → matches the letter “a”
  • . → matches any character
  • \d → matches a digit (0–9)
  • \w → matches a letter or digit
  • * → “0 or more times”
  • + → “1 or more times”



A RegEx example


Let’s go back to our example.


We want to target only the homepage:https://www.example.com


The corresponding RegEx would be:

^https://www\.example\.com$

Explanation:



In the Dashboard

With this RegEx, the element will only be displayed if the URL is exactly:


It will not display if there are any characters before or after (such as tracking parameters).



Including tracking parameters

If you want to target the homepage including optional tracking parameters, use:

^https://www\.example\.com(\?.*)?$

Explanation:

  • ^ → start of the string
  • https://www\.example\.com → exact domain
  • (\?.*)? → optional part:
    • \? → the ? used in URL parameters (escaped)
    • .* → any characters after
    • ? (outside) → makes the whole group optional
  • $ → end of the string



Testing your RegEx

When creating your regular expressions, you can test them to see which URLs will match.

You can use online tools such as:



Tip : to save time, you can also use LLMs to help generate your regular expressions.



Need help?

If you have any questions, feel free to reach out to the team!

Updated on: 22/04/2026

Was this article helpful?

Share your feedback

Cancel

Thank you!