Regular Expressions (RegEx) are advanced search patterns to match multiple URLs by providing conditions. This match type helps in defining a search pattern in which the Experiments should run.
Regex is the most complex form of URL targeting and requires the use of regular expressions. Using different regular expressions, you can target a wide range of pages. This form of URL targeting is the most helpful for targeting multiple pages simultaneously.
Given below are some of the examples in RegEx match type:
- Example 1: Targeting all the pages in a specific URL
To target all the pages in a URL - https://www.test.com/app/
You can use the regex pattern:
https://www.test.com/app/.*
- Example 2: Targeting the pages ending with numbers
To target URLs such as
You can use the regex pattern:
https://www.test.com/app-[0-9]+/
- Example 3: Targeting the pages with particular word in it
To target the pages in a domain with a particular word such as,
You can use the regex pattern:
https://test.com/app[a-z0-9]*.html
- Example 4: Targeting either of the pages
To target pages with either of terms in the domain such as,
You can use the regex pattern:
- Example 5: Targeting by excluding a group of similar pages
To target all the pages except a page or set of pages with certain string in it such as,
You can use the regex pattern:
https://test.com/app/(?!uk).*/products
By using the above-mentioned regex pattern, you can exclude all the pages with UK string after the /app/ in the domain URL. Some of the pages(example) which will be tracked are:
- https://test.com/app/usa/products
- https://test.com/app/australia/products
- https://test.com/app/india/products
- Example 6: Targeting complex pages
To target complex set of URLs such as
You can use the regex pattern:
https?://(www.)?test.com/.*/(categories|products)/.*
RegEx characters used in the above example are explained as follows
https? - Tracks both http as well as https
(www.)? - Tracks the pages with our without www in the URL
Here, both http://www.test.com and https://test.com will be tracked