DBE7
DBE7

Reputation: 816

How to use regex for URL-targeting

As a disclaimer, I must say that my experience with regular expressions is very limited. I am using Optimizely for A/B testing and have run into a problem. I only want my experiment to run on one page, however, this page's URL-structure is somewhat complicated. The URL-structure of the page where I want to run my experiment looks like this:

https://mywebsite.co/term/public_id/edit/pricing

The problem is the public_id that changes dynamically, whenever a new user goes through the signup flow. How can I use regex to target this page exclusively? I have been trying to figure it out these past days but without any luck. Optimizely regex docs can be found here. I can't just use a simple match because /term/ appears in the URL of several pages on my site.

Upvotes: 0

Views: 1180

Answers (1)

trincot
trincot

Reputation: 350310

You could use this regular expression:

 mywebsite\.co/somepage/.*?/edit/pricing

The .* part means any character can occur here any number of times. The additional ? makes it lazy, meaning the rest of the regular expression will kick in as soon as possible.

Note that a literal . needs to be escaped with a backslash, like \.

Upvotes: 2

Related Questions